{"cells":[{"metadata":{},"cell_type":"markdown","source":"# **APTOS 2019 Blindness Detection**"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false},"cell_type":"markdown","source":"## Goal\nYou are provided with a large set of retina images taken using **fundus photography** under a variety of imaging conditions.\n\nA clinician has rated each image for the severity of **diabetic retinopathy** on a scale of 0 to 4:\n\n    0 - No DR\n\n    1 - Mild\n\n    2 - Moderate\n\n    3 - Severe\n\n    4 - Proliferative DR\n"},{"metadata":{},"cell_type":"markdown","source":"## Terminology\n### Fundus photography\nFundus photography involves photographing the rear of an eye; also known as the fundus. Specialized fundus cameras consisting of an intricate microscope attached to a flash enabled camera are used in fundus photography.\n\nNormal Retina\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Fundus_photograph_of_normal_right_eye.jpg/250px-Fundus_photograph_of_normal_right_eye.jpg\">\n\n\n### Diabetic retinopathy\nDR is a complication of diabetes and a leading cause of blindness.\n\nThe retina is the membrane that covers the back of the eye. It is highly sensitive to light.\n\nIt converts any light that hits the eye into signals that can be interpreted by the brain. This process produces visual images, and it is how sight functions in the human eye.\n\nDiabetic retinopathy damages the blood vessels within the retinal tissue, causing them to leak fluid and distort vision.\n\n<img src=\"https://www.researchgate.net/profile/Seifedine_Kadry/publication/332306977/figure/fig1/AS:746768480350209@1555054888666/Normal-retina-and-DR-affected-retina.ppm\" width=\"500px\">"},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2\nimport seaborn as sns\ndf = pd.read_csv('../input/train.csv')\n\n\nCases = {\n            'No_DR' : df['id_code'][df['diagnosis']==0][:9],\n            'Mild' : df['id_code'][df['diagnosis']==1][:9],\n            'Moderate' : df['id_code'][df['diagnosis']==2][:9],\n            'Severe' : df['id_code'][df['diagnosis']==3][:9],\n            'Proliferative_DR' : df['id_code'][df['diagnosis']==4][:9]\n}\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def readImg(lis):\n    ret = []\n    for i in lis:\n        img = cv2.resize(cv2.cvtColor(cv2.imread('../input/train_images/'+i+'.png'), cv2.COLOR_BGR2RGB), (300,300))\n        ret.append(img)\n    return ret","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### No DR Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3, figsize=(20,20))\nt=list(Cases)[0]\nlis = readImg(Cases[t])\nfor i in range(3):\n    for j in range(3):\n        ax[i][j].imshow(lis[i*3+j])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Mild Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3, figsize=(20,20))\nt=list(Cases)[1]\nlis = readImg(Cases[t])\nfor i in range(3):\n    for j in range(3):\n        ax[i][j].imshow(lis[i*3+j])\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Moderate Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3, figsize=(20,20))\nt=list(Cases)[2]\nlis = readImg(Cases[t])\nfor i in range(3):\n    for j in range(3):\n        ax[i][j].imshow(lis[i*3+j])\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Severe Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3, figsize=(20,20))\nt=list(Cases)[3]\nlis = readImg(Cases[t])\nfor i in range(3):\n    for j in range(3):\n        ax[i][j].imshow(lis[i+j])\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Proliferative DR Image\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3, figsize=(20,20))\nt=list(Cases)[4]\nlis = readImg(Cases[t])\nfor i in range(3):\n    for j in range(3):\n        ax[i][j].imshow(lis[i*3+j])\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(df.diagnosis)\nplt.title(\"Distrubation of Classes\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.diagnosis.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"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.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}