{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n!pwd\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0516c79561f464afc4e47a4d98927c498ada8682"},"cell_type":"code","source":"!ls ../input","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import pandas as pd\nfrom sklearn import preprocessing\nimport os\nimport cv2\nfrom PIL import Image\nimport pickle\ndir_num = '../input' ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"3dbe009defe621b395d67483f558fe7c55aa1de6"},"cell_type":"code","source":"import numpy as np\ndef variance_of_laplacian(image):\n    # compute the Laplacian of the image and then return the focus\n    # measure, which is simply the variance of the Laplacian\n    image = np.array(image) \n    return cv2.Laplacian(image, cv2.CV_64F).var()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5a96dce564874dc6eb027c08fb3f9426e5cc6a7f"},"cell_type":"code","source":"list_of_images = os.listdir(dir_num)\nprint(list_of_images)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aa88e0d0ae4812e4901f15929689f0f91f4ebdea"},"cell_type":"code","source":"mapping = {}\ndef function1(file):\n    dir_num = '../input'\n    file_name = file.split(\".\")[0]\n    fm = 0\n    if file.split(\".\")[1]!='jpg':\n        return fm\n    try:\n        gray = Image.open(os.path.abspath('/kaggle/working/'+dir_num+\"/\"+file)).convert('LA')\n        fm = variance_of_laplacian(gray)\n        #print(fm)\n        #mapping[file_name] = fm \n    except:\n        print(\"Error out\")\n    return (file,fm)\nimport multiprocessing\nimport sys\npool = multiprocessing.Pool()\n#blur_list = pool.map(function1,list_of_images)\nblur_list = []\nfor i, output in enumerate(pool.imap_unordered(function1,list_of_images), 1):\n    sys.stderr.write('\\rdone {0:%}'.format(i/len(list_of_images)))\n    blur_list.append(output)\nprint(blur_list)\n# for idx,file in enumerate(list_of_images):\n#     print(idx)\n#     file_name = file.split(\".\")[0]\n#     if file.split(\".\")[1]!='jpg':\n#         continue\n#     try:\n#         gray = Image.open(os.path.abspath('../'+dir_num+\"/\"+file)).convert('LA')\n#         fm = variance_of_laplacian(gray)\n#         print(fm)\n#         mapping[file_name] = fm \n#     except:\n#         print(\"Error out\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"275d2baa0223cce5ce82dc6b303a7ebf8de6fc9b"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}