{"cells":[{"metadata":{},"cell_type":"markdown","source":"**APTOS 2019 Blindness Detection**\nDiabetic eye disease can affect many parts of the eye, including the retina, macula, lens and the optic nerve.\nDiabetic eye disease is a group of eye conditions that can affect people with diabetes.\n\nDiabetic retinopathy affects blood vessels in the light-sensitive tissue called the retina that lines the back of the eye. It is the most common cause of vision loss among people with diabetes and the leading cause of vision impairment and blindness among working-age adults.\nDiabetic macular edema (DME). A consequence of diabetic retinopathy, DME is swelling in an area of the retina called the macula.\n\nA clinician has rated each image for the severity of diabetic retinopathy on a scale of 0 to 4:\n\n0 - No DR\n\n1 - Mild\n\n2 - Moderate\n\n3 - Severe\n\n4 - Proliferative DR"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport os\nimport cv2\nimport tensorflow as tf\nfrom PIL import Image\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_path = os.path.join('..','input/train_images/')\ndf_train = pd.read_csv(\"../input/train.csv\")\ndf_train['path'] = df_train['id_code'].map(lambda x: os.path.join(train_path,'{}.png'.format(x)))\ndf_train = df_train.drop(columns=['id_code'])\ndf_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#df_test = pd.read_csv(\"../input/train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(df_train['diagnosis'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def subtract_median_bg_image(im):\n    k = np.max(im.shape)//20*2+1\n    bg = cv2.medianBlur(im, k)\n    return cv2.addWeighted (im, 4, bg, -4, 128)\n\ndef subtract_gaussian_bg_image(im):\n    k = np.max(im.shape)/10\n    bg = cv2.GaussianBlur(im ,(0,0) ,k)\n    return cv2.addWeighted (im, 4, bg, -4, 128)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(2, 5, figsize=(20, 10))\nax = ax.flatten()\nfor i in range(10):\n    path = df_train['path'][i]\n    img = cv2.imread(path)\n    img  = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)\n    img = cv2.resize(img,(512,512))\n    ax[i].imshow(img)\n    ax[i].set_title(df_train['diagnosis'][i])\n    \nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(5, 5, figsize=(20, 20))\nax = ax.flatten()\nfor i in range(25):\n    path = df_train['path'][i]\n    img = cv2.imread(path)\n    #img  = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n    img = cv2.resize(img,(512,512))\n    img = subtract_median_bg_image(img)\n    ax[i].imshow(img)\n    ax[i].set_title(df_train['diagnosis'][i])\n    \nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":false,"_kg_hide-output":false,"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(5, 5, figsize=(20, 20))\nax = ax.flatten()\nfor i in range(25):\n    path = df_train['path'][i]\n    img = cv2.imread(path)\n    #img  = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n    img = cv2.resize(img,(512,512))\n    #img = subtract_gaussian_bg_image(img)\n    #img = subtract_median_bg_image(img)\n    img = subtract_gaussian_bg_image(img)\n    \n    ax[i].imshow(img)\n    ax[i].set_title(df_train['diagnosis'][i])\n    \nplt.show()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}