{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\n\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport keras\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom matplotlib import pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"IMAGE_SHAPE = (224, 224, 3)\nIMAGE_SIZE = (224, 224)\n\ndef preprocess_image(image):\n    \n    image = cv2.addWeighted(image, 4, cv2.GaussianBlur(image, (0, 0), 30), -4, 128)\n    \n    height, width, _ = image.shape\n    center_x = int(width / 2)\n    center_y = int(height / 2)\n    radius = min(center_x, center_y)\n    \n    circle_mask = np.zeros((height, width), np.uint8)\n    cv2.circle(circle_mask, (center_x, center_y), radius, color=1, thickness=-1)\n    image = cv2.resize(cv2.bitwise_and(image, image, mask=circle_mask)[center_y - radius:center_y + radius, center_x - radius:center_x + radius], IMAGE_SIZE)\n    \n    return image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.mkdir(\"/kaggle/processed\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.mkdir(\"/kaggle/processed/train_images\")\nos.mkdir(\"/kaggle/processed/test_images\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_path = \"../input/aptos2019-blindness-detection/train_images\"\ntest_path = \"../input/aptos2019-blindness-detection/test_images\"\ndst_train_path = \"/kaggle/processed/train_images\"\ndst_test_path = \"/kaggle/processed/test_images\"\n\nfor image_name in os.listdir(train_path):\n    image_path = os.path.join(train_path, image_name)\n    image = cv2.imread(image_path)\n    image = preprocess_image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n    cv2.imwrite(os.path.join(dst_train_path, image_name), image)\n\nfor image_name in os.listdir(test_path):\n    image_path = os.path.join(test_path, image_name)\n    image = cv2.imread(image_path)\n    image = preprocess_image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n    cv2.imwrite(os.path.join(dst_test_path, image_name), image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.listdir(dst_train_path)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample = cv2.imread(os.path.join(dst_train_path, '0c43c79e8cfb.png'))\nplt.imshow(sample)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}