{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport tensorflow as tf \n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-16T16:20:28.908881Z","iopub.execute_input":"2022-12-16T16:20:28.909296Z","iopub.status.idle":"2022-12-16T16:20:28.915438Z","shell.execute_reply.started":"2022-12-16T16:20:28.909263Z","shell.execute_reply":"2022-12-16T16:20:28.914029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"###  CSV belgerini inceleme","metadata":{}},{"cell_type":"code","source":"path = \"/kaggle/input/aptos2019-blindness-detection\"\ndf = pd.read_csv(path + \"/train.csv\")\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:28.921737Z","iopub.execute_input":"2022-12-16T16:20:28.922971Z","iopub.status.idle":"2022-12-16T16:20:28.942049Z","shell.execute_reply.started":"2022-12-16T16:20:28.922926Z","shell.execute_reply":"2022-12-16T16:20:28.941094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"diagnosis\"].hist()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:28.943618Z","iopub.execute_input":"2022-12-16T16:20:28.944701Z","iopub.status.idle":"2022-12-16T16:20:29.198273Z","shell.execute_reply.started":"2022-12-16T16:20:28.944665Z","shell.execute_reply":"2022-12-16T16:20:29.196963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"diagnosis\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:29.201915Z","iopub.execute_input":"2022-12-16T16:20:29.203277Z","iopub.status.idle":"2022-12-16T16:20:29.214269Z","shell.execute_reply.started":"2022-12-16T16:20:29.203216Z","shell.execute_reply":"2022-12-16T16:20:29.212668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.sort_values(by = [\"id_code\"])\ndf.head()\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:29.216816Z","iopub.execute_input":"2022-12-16T16:20:29.217237Z","iopub.status.idle":"2022-12-16T16:20:29.235138Z","shell.execute_reply.started":"2022-12-16T16:20:29.217202Z","shell.execute_reply":"2022-12-16T16:20:29.233419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Görütüleri Okuma","metadata":{}},{"cell_type":"code","source":"import os\nimport cv2\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:29.237771Z","iopub.execute_input":"2022-12-16T16:20:29.238997Z","iopub.status.idle":"2022-12-16T16:20:29.245000Z","shell.execute_reply.started":"2022-12-16T16:20:29.238936Z","shell.execute_reply":"2022-12-16T16:20:29.243791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files_train_imgs = os.listdir(path + \"/train_images\")\nfiles_train_imgs\nlen(files_train_imgs)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:29.246739Z","iopub.execute_input":"2022-12-16T16:20:29.247444Z","iopub.status.idle":"2022-12-16T16:20:29.261952Z","shell.execute_reply.started":"2022-12-16T16:20:29.247397Z","shell.execute_reply":"2022-12-16T16:20:29.260996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_list = []\n\nfor i in files_train_imgs[0:20]:\n    image = cv2.imread(path + \"/train_images/\" + i)\n    image = cv2.resize(image,(400,400) )\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    img_list.append(image)\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:29.263950Z","iopub.execute_input":"2022-12-16T16:20:29.264363Z","iopub.status.idle":"2022-12-16T16:20:31.302083Z","shell.execute_reply.started":"2022-12-16T16:20:29.264328Z","shell.execute_reply":"2022-12-16T16:20:31.300488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(img_list)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.304187Z","iopub.execute_input":"2022-12-16T16:20:31.304844Z","iopub.status.idle":"2022-12-16T16:20:31.314866Z","shell.execute_reply.started":"2022-12-16T16:20:31.304787Z","shell.execute_reply":"2022-12-16T16:20:31.312985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img_list[4])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.317246Z","iopub.execute_input":"2022-12-16T16:20:31.317832Z","iopub.status.idle":"2022-12-16T16:20:31.576437Z","shell.execute_reply.started":"2022-12-16T16:20:31.317782Z","shell.execute_reply":"2022-12-16T16:20:31.575019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ön işleme\n","metadata":{}},{"cell_type":"markdown","source":"#### Gaussian Blur","metadata":{}},{"cell_type":"markdown","source":"Threshold, sağlanan eşik değerine göre pikseel değerlerinin atanması olan OpenCV'de bir tekniktir. Threshold'da, her piksel değeri, eşik değeri ile karşılaştırlırç Piksel değeri eşkten küçüks, 0'a aayalanır, aksi takdirde maksimum değere (genellikle255) ayarlanır. Amacımız siyah kısmı alarak resimlerdeki segementasyon yapacağız bir nevi","metadata":{}},{"cell_type":"code","source":"kopya = img_list[4].copy()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.580863Z","iopub.execute_input":"2022-12-16T16:20:31.581274Z","iopub.status.idle":"2022-12-16T16:20:31.588078Z","shell.execute_reply.started":"2022-12-16T16:20:31.581241Z","shell.execute_reply":"2022-12-16T16:20:31.586761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kopya = cv2.cvtColor(kopya, cv2.COLOR_RGB2GRAY)\nplt.imshow(kopya,cmap=\"gray\")\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.589500Z","iopub.execute_input":"2022-12-16T16:20:31.589879Z","iopub.status.idle":"2022-12-16T16:20:31.859160Z","shell.execute_reply.started":"2022-12-16T16:20:31.589844Z","shell.execute_reply":"2022-12-16T16:20:31.857644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kopya.shape # resimimiz tek boyutta indirgenmiş oldu bir nevi r,g,b den kurtulmuş oldu.","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.861034Z","iopub.execute_input":"2022-12-16T16:20:31.862290Z","iopub.status.idle":"2022-12-16T16:20:31.870345Z","shell.execute_reply.started":"2022-12-16T16:20:31.862233Z","shell.execute_reply":"2022-12-16T16:20:31.868623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"burda kullanacağımız blur datanın ana hattını korumaya devam ediyor ","metadata":{}},{"cell_type":"code","source":"blur = cv2.GaussianBlur(kopya, (5,5), 0)\nplt.imshow(blur, cmap=\"gray\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:31.872189Z","iopub.execute_input":"2022-12-16T16:20:31.872649Z","iopub.status.idle":"2022-12-16T16:20:32.105451Z","shell.execute_reply.started":"2022-12-16T16:20:31.872595Z","shell.execute_reply":"2022-12-16T16:20:32.103981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nthresh = cv2.threshold(blur, 10,255, cv2.THRESH_BINARY)[1]\nplt.imshow(thresh,cmap=\"gray\")","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.107488Z","iopub.execute_input":"2022-12-16T16:20:32.108033Z","iopub.status.idle":"2022-12-16T16:20:32.362941Z","shell.execute_reply.started":"2022-12-16T16:20:32.107987Z","shell.execute_reply":"2022-12-16T16:20:32.361317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Kontur Bulma","metadata":{}},{"cell_type":"markdown","source":"CV_RETR_EXTERNAL -> Sadece dış katmandaki konturları verir.\n\nCV_RETR_LIST -> Tğm konturları ve hiyerarsiyi hesaplaması yapmaz\n\nCV_RETR_CCOMP -> kontur verir ve iç ve dış olmak üzere ayırır.\n\nCV_RETR_TREE -> konturların tüm hiyerarşisini hesaplar.","metadata":{}},{"cell_type":"code","source":"kontur = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.364707Z","iopub.execute_input":"2022-12-16T16:20:32.365142Z","iopub.status.idle":"2022-12-16T16:20:32.375365Z","shell.execute_reply.started":"2022-12-16T16:20:32.365107Z","shell.execute_reply":"2022-12-16T16:20:32.374091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kontur = kontur[0][0]\nkontur.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.377211Z","iopub.execute_input":"2022-12-16T16:20:32.377789Z","iopub.status.idle":"2022-12-16T16:20:32.389948Z","shell.execute_reply.started":"2022-12-16T16:20:32.377732Z","shell.execute_reply":"2022-12-16T16:20:32.388375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kontur = kontur[:,0,:]\nkontur.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.391504Z","iopub.execute_input":"2022-12-16T16:20:32.392022Z","iopub.status.idle":"2022-12-16T16:20:32.401266Z","shell.execute_reply.started":"2022-12-16T16:20:32.391973Z","shell.execute_reply":"2022-12-16T16:20:32.400025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"kontur[:,0].argmin()\n","metadata":{"execution":{"iopub.status.busy":"2022-12-14T22:26:23.803357Z","iopub.execute_input":"2022-12-14T22:26:23.803871Z","iopub.status.idle":"2022-12-14T22:26:23.813705Z","shell.execute_reply.started":"2022-12-14T22:26:23.803836Z","shell.execute_reply":"2022-12-14T22:26:23.812374Z"}}},{"cell_type":"code","source":"kontur[92]","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.403085Z","iopub.execute_input":"2022-12-16T16:20:32.403493Z","iopub.status.idle":"2022-12-16T16:20:32.412717Z","shell.execute_reply.started":"2022-12-16T16:20:32.403459Z","shell.execute_reply":"2022-12-16T16:20:32.411581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sol = tuple(kontur[kontur[:,0].argmin()])\nsag = tuple(kontur[kontur[:,0].argmax()])\nust = tuple(kontur[kontur[:,1].argmin()])\nalt = tuple(kontur[kontur[:,1].argmax()])\n\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.414336Z","iopub.execute_input":"2022-12-16T16:20:32.414731Z","iopub.status.idle":"2022-12-16T16:20:32.423841Z","shell.execute_reply.started":"2022-12-16T16:20:32.414697Z","shell.execute_reply":"2022-12-16T16:20:32.422489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sol, sag, ust, alt ","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.425513Z","iopub.execute_input":"2022-12-16T16:20:32.426403Z","iopub.status.idle":"2022-12-16T16:20:32.437213Z","shell.execute_reply.started":"2022-12-16T16:20:32.426324Z","shell.execute_reply":"2022-12-16T16:20:32.436248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x1 = sol[0]\ny1 = ust[1]\nx2 = sag[0]\ny2 = alt[1]","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.438399Z","iopub.execute_input":"2022-12-16T16:20:32.438856Z","iopub.status.idle":"2022-12-16T16:20:32.448982Z","shell.execute_reply.started":"2022-12-16T16:20:32.438810Z","shell.execute_reply":"2022-12-16T16:20:32.447619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x1,y1,x2,y2","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.450924Z","iopub.execute_input":"2022-12-16T16:20:32.451408Z","iopub.status.idle":"2022-12-16T16:20:32.465629Z","shell.execute_reply.started":"2022-12-16T16:20:32.451370Z","shell.execute_reply":"2022-12-16T16:20:32.464105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"original = img_list[4].copy()\nplt.imshow(original)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.467349Z","iopub.execute_input":"2022-12-16T16:20:32.467799Z","iopub.status.idle":"2022-12-16T16:20:32.760579Z","shell.execute_reply.started":"2022-12-16T16:20:32.467762Z","shell.execute_reply":"2022-12-16T16:20:32.759486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"crop_ilk = original[y1:y2, x1:x2]\nprint(crop_ilk.shape)\nplt.imshow(crop_ilk)\nplt.show()\ncrop_ilk = cv2.resize(crop_ilk, (400,400))\n\nplt.imshow(crop_ilk)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:32.762122Z","iopub.execute_input":"2022-12-16T16:20:32.762792Z","iopub.status.idle":"2022-12-16T16:20:33.280737Z","shell.execute_reply.started":"2022-12-16T16:20:32.762751Z","shell.execute_reply":"2022-12-16T16:20:33.279536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"crop_ilk.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.282255Z","iopub.execute_input":"2022-12-16T16:20:33.286296Z","iopub.status.idle":"2022-12-16T16:20:33.294396Z","shell.execute_reply.started":"2022-12-16T16:20:33.286245Z","shell.execute_reply":"2022-12-16T16:20:33.293188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = int(x2-x1)*4 // 100\ny = int(y2-y1)*5 // 100\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.296717Z","iopub.execute_input":"2022-12-16T16:20:33.298184Z","iopub.status.idle":"2022-12-16T16:20:33.306318Z","shell.execute_reply.started":"2022-12-16T16:20:33.298125Z","shell.execute_reply":"2022-12-16T16:20:33.304433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x,y","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.308469Z","iopub.execute_input":"2022-12-16T16:20:33.309612Z","iopub.status.idle":"2022-12-16T16:20:33.318118Z","shell.execute_reply.started":"2022-12-16T16:20:33.309572Z","shell.execute_reply":"2022-12-16T16:20:33.316675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"crop_son = original[y+y1 : y2-y, x1+x : x2-x]\nplt.imshow(crop_son)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.325901Z","iopub.execute_input":"2022-12-16T16:20:33.326340Z","iopub.status.idle":"2022-12-16T16:20:33.614743Z","shell.execute_reply.started":"2022-12-16T16:20:33.326304Z","shell.execute_reply":"2022-12-16T16:20:33.613272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"crop_son = cv2.resize(\"crop_son, (400,400))","metadata":{}},{"cell_type":"code","source":"crop_son = cv2.resize(crop_son, (400,400))\nplt.imshow(crop_son)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.616620Z","iopub.execute_input":"2022-12-16T16:20:33.617066Z","iopub.status.idle":"2022-12-16T16:20:33.912055Z","shell.execute_reply.started":"2022-12-16T16:20:33.617027Z","shell.execute_reply":"2022-12-16T16:20:33.910324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Clahe - Kontrast Limitli Adaptif Histogram Eşitleme","metadata":{}},{"cell_type":"markdown","source":"Histogram eşitleme, tkontrastı iyileştimek için kullanılan bir görüntü işleme tekniğidir. Bunu, diğerlerin en yoğun olduğu bölgeyi komşularına yayarak, yani görüntünün yoğunluk aralığın uzatarak gerçekleştirir.","metadata":{}},{"cell_type":"code","source":"lab = cv2.cvtColor(crop_son, cv2.COLOR_RGB2LAB)\nlab.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.914696Z","iopub.execute_input":"2022-12-16T16:20:33.915518Z","iopub.status.idle":"2022-12-16T16:20:33.926165Z","shell.execute_reply.started":"2022-12-16T16:20:33.915478Z","shell.execute_reply":"2022-12-16T16:20:33.924818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l,a,b = cv2.split(lab) \nplt.imshow(l, cmap=\"gray\")\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:33.927908Z","iopub.execute_input":"2022-12-16T16:20:33.929146Z","iopub.status.idle":"2022-12-16T16:20:34.188526Z","shell.execute_reply.started":"2022-12-16T16:20:33.929099Z","shell.execute_reply":"2022-12-16T16:20:34.187051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"l.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.190088Z","iopub.execute_input":"2022-12-16T16:20:34.190449Z","iopub.status.idle":"2022-12-16T16:20:34.197998Z","shell.execute_reply.started":"2022-12-16T16:20:34.190414Z","shell.execute_reply":"2022-12-16T16:20:34.196914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"düz = l.flatten() # datamızı tek boyuta sokar","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.199214Z","iopub.execute_input":"2022-12-16T16:20:34.199835Z","iopub.status.idle":"2022-12-16T16:20:34.207908Z","shell.execute_reply.started":"2022-12-16T16:20:34.199798Z","shell.execute_reply":"2022-12-16T16:20:34.206706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"düz.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.209940Z","iopub.execute_input":"2022-12-16T16:20:34.210500Z","iopub.status.idle":"2022-12-16T16:20:34.221648Z","shell.execute_reply.started":"2022-12-16T16:20:34.210455Z","shell.execute_reply":"2022-12-16T16:20:34.220666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(düz, 25,[0,255], color=\"r\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.223057Z","iopub.execute_input":"2022-12-16T16:20:34.223408Z","iopub.status.idle":"2022-12-16T16:20:34.467682Z","shell.execute_reply.started":"2022-12-16T16:20:34.223376Z","shell.execute_reply":"2022-12-16T16:20:34.466044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clahe = cv2.createCLAHE(clipLimit=7.0, tileGridSize=((8,8)))\ncl = clahe.apply(l)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.469616Z","iopub.execute_input":"2022-12-16T16:20:34.470110Z","iopub.status.idle":"2022-12-16T16:20:34.483287Z","shell.execute_reply.started":"2022-12-16T16:20:34.470064Z","shell.execute_reply":"2022-12-16T16:20:34.482173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(cl.flatten(), 25, [0,256], color=\"r\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.484422Z","iopub.execute_input":"2022-12-16T16:20:34.484791Z","iopub.status.idle":"2022-12-16T16:20:34.741753Z","shell.execute_reply.started":"2022-12-16T16:20:34.484741Z","shell.execute_reply":"2022-12-16T16:20:34.740023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(cl)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:34.743666Z","iopub.execute_input":"2022-12-16T16:20:34.744066Z","iopub.status.idle":"2022-12-16T16:20:35.042934Z","shell.execute_reply.started":"2022-12-16T16:20:34.744033Z","shell.execute_reply":"2022-12-16T16:20:35.041607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(l)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:35.044440Z","iopub.execute_input":"2022-12-16T16:20:35.045600Z","iopub.status.idle":"2022-12-16T16:20:35.341973Z","shell.execute_reply.started":"2022-12-16T16:20:35.045540Z","shell.execute_reply":"2022-12-16T16:20:35.337224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"limg = cv2.merge((cl,a,b))","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:35.345180Z","iopub.execute_input":"2022-12-16T16:20:35.345768Z","iopub.status.idle":"2022-12-16T16:20:35.353709Z","shell.execute_reply.started":"2022-12-16T16:20:35.345709Z","shell.execute_reply":"2022-12-16T16:20:35.351867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"son = cv2.cvtColor(limg, cv2.COLOR_LAB2RGB)\nplt.imshow(son)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:35.355947Z","iopub.execute_input":"2022-12-16T16:20:35.356899Z","iopub.status.idle":"2022-12-16T16:20:36.201974Z","shell.execute_reply.started":"2022-12-16T16:20:35.356841Z","shell.execute_reply":"2022-12-16T16:20:36.200418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(crop_son)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:36.203823Z","iopub.execute_input":"2022-12-16T16:20:36.204303Z","iopub.status.idle":"2022-12-16T16:20:36.503789Z","shell.execute_reply.started":"2022-12-16T16:20:36.204257Z","shell.execute_reply":"2022-12-16T16:20:36.502791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Median Blur","metadata":{}},{"cell_type":"code","source":"arka_plan =cv2.medianBlur(son,23)\nplt.imshow(arka_plan)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:36.505037Z","iopub.execute_input":"2022-12-16T16:20:36.505914Z","iopub.status.idle":"2022-12-16T16:20:36.791179Z","shell.execute_reply.started":"2022-12-16T16:20:36.505869Z","shell.execute_reply":"2022-12-16T16:20:36.789771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"med_son =cv2.medianBlur(son,3)\nplt.imshow(med_son)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:36.792737Z","iopub.execute_input":"2022-12-16T16:20:36.793360Z","iopub.status.idle":"2022-12-16T16:20:37.047791Z","shell.execute_reply.started":"2022-12-16T16:20:36.793324Z","shell.execute_reply":"2022-12-16T16:20:37.046484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mask = cv2.addWeighted(med_son, 0.1,arka_plan, 0.1,0)\nplt.imshow(mask)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:37.049758Z","iopub.execute_input":"2022-12-16T16:20:37.050150Z","iopub.status.idle":"2022-12-16T16:20:37.302369Z","shell.execute_reply.started":"2022-12-16T16:20:37.050113Z","shell.execute_reply":"2022-12-16T16:20:37.301114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mask2 = cv2.addWeighted(med_son, 1,arka_plan, -0.7,0)\nplt.imshow(mask2)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:37.304240Z","iopub.execute_input":"2022-12-16T16:20:37.304832Z","iopub.status.idle":"2022-12-16T16:20:37.566031Z","shell.execute_reply.started":"2022-12-16T16:20:37.304793Z","shell.execute_reply":"2022-12-16T16:20:37.565058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mask3 = cv2.addWeighted(med_son,0,arka_plan,-1,255)\nplt.imshow(mask3)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:37.567239Z","iopub.execute_input":"2022-12-16T16:20:37.568366Z","iopub.status.idle":"2022-12-16T16:20:37.858209Z","shell.execute_reply.started":"2022-12-16T16:20:37.568321Z","shell.execute_reply":"2022-12-16T16:20:37.856627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"son_img = cv2.bitwise_and(mask3, med_son)\nplt.imshow(son_img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:37.860166Z","iopub.execute_input":"2022-12-16T16:20:37.860537Z","iopub.status.idle":"2022-12-16T16:20:38.118641Z","shell.execute_reply.started":"2022-12-16T16:20:37.860503Z","shell.execute_reply":"2022-12-16T16:20:38.117097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(med_son)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:20:38.120362Z","iopub.execute_input":"2022-12-16T16:20:38.120867Z","iopub.status.idle":"2022-12-16T16:20:38.413140Z","shell.execute_reply.started":"2022-12-16T16:20:38.120814Z","shell.execute_reply":"2022-12-16T16:20:38.411660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Ön işleme kodlarını toplama ","metadata":{}},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_list = [];\n\nfor i in files_train_imgs[0:20]:\n    image = cv2.imread(path + \"/train_images/\" + i)\n    image = cv2.resize(image,(400,400))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    kopya = image.copy()\n    kopya = cv2.cvtColor(kopya, cv2.COLOR_RGB2GRAY)\n    blur = cv2.GaussianBlur(kopya, (5,5), 6)\n    thresh = cv2.threshold(blur,10,255,cv2.THRESH_BINARY)[1]\n    kontur = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)\n    kontur = kontur[0][0]\n    kontur = kontur[:,0,:]\n    x1 = tuple(kontur[kontur[:,0].argmin()])[0]\n    y1 = tuple(kontur[kontur[:,1].argmin()])[1]\n    x2 = tuple(kontur[kontur[:,0].argmax()])[0]\n    y2 = tuple(kontur[kontur[:,0].argmax()])[1]\n    x = int(x2-x1)*4//50\n    y = int(y2-y1)*5//50\n    kopya2 = image.copy()\n    #kopya2 = kopya2[y1+y : y2-y, x1+x: x2-x]\n    kopya2 = cv2.resize(kopya2,(400,400))\n    lab = cv2.cvtColor(kopya2,cv2.COLOR_RGB2LAB)\n    l,a,b = cv2.split(lab)\n    clahe = cv2.createCLAHE(clipLimit=5.0, tileGridSize=((8,8)))\n    cl = clahe.apply(l)\n    limg = cv2.merge((cl,a,b))\n    son = cv2.cvtColor(limg, cv2.COLOR_LAB2RGB)\n    med_son = cv2.medianBlur(son,3)\n    arka_plan = cv2.medianBlur(son, 37)\n    maske = cv2.addWeighted(med_son, 1, arka_plan, -1, 255)\n    son_img = cv2.bitwise_and(maske, med_son)\n    img_list.append(son_img)","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:28:57.934023Z","iopub.execute_input":"2022-12-16T16:28:57.934517Z","iopub.status.idle":"2022-12-16T16:29:00.621741Z","shell.execute_reply.started":"2022-12-16T16:28:57.934482Z","shell.execute_reply":"2022-12-16T16:29:00.620497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img_list[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:37:53.804552Z","iopub.execute_input":"2022-12-16T16:37:53.805345Z","iopub.status.idle":"2022-12-16T16:37:54.051450Z","shell.execute_reply.started":"2022-12-16T16:37:53.805305Z","shell.execute_reply":"2022-12-16T16:37:54.050056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img_list[4])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:38:15.415526Z","iopub.execute_input":"2022-12-16T16:38:15.416062Z","iopub.status.idle":"2022-12-16T16:38:15.682084Z","shell.execute_reply.started":"2022-12-16T16:38:15.416014Z","shell.execute_reply":"2022-12-16T16:38:15.680404Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(20, 12))\n\nfor i in range(12):\n    img = img_list[i]\n    fig.add_subplot(3,4,i+1)\n    plt.imshow(img)\n    \nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:41:00.669197Z","iopub.execute_input":"2022-12-16T16:41:00.669721Z","iopub.status.idle":"2022-12-16T16:41:03.549738Z","shell.execute_reply.started":"2022-12-16T16:41:00.669681Z","shell.execute_reply":"2022-12-16T16:41:03.548663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### One Hot Encoding","metadata":{}},{"cell_type":"code","source":"df[\"diagnosis\"]","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:42:25.269648Z","iopub.execute_input":"2022-12-16T16:42:25.270100Z","iopub.status.idle":"2022-12-16T16:42:25.284569Z","shell.execute_reply.started":"2022-12-16T16:42:25.270067Z","shell.execute_reply":"2022-12-16T16:42:25.282728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = pd.get_dummies(df[\"diagnosis\"]).values","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:43:13.195716Z","iopub.execute_input":"2022-12-16T16:43:13.196208Z","iopub.status.idle":"2022-12-16T16:43:13.206612Z","shell.execute_reply.started":"2022-12-16T16:43:13.196171Z","shell.execute_reply":"2022-12-16T16:43:13.205159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:43:16.737353Z","iopub.execute_input":"2022-12-16T16:43:16.737830Z","iopub.status.idle":"2022-12-16T16:43:16.747076Z","shell.execute_reply.started":"2022-12-16T16:43:16.737794Z","shell.execute_reply":"2022-12-16T16:43:16.745740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"diagnosis\"][1]\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:44:35.053100Z","iopub.execute_input":"2022-12-16T16:44:35.053638Z","iopub.status.idle":"2022-12-16T16:44:35.062436Z","shell.execute_reply.started":"2022-12-16T16:44:35.053596Z","shell.execute_reply":"2022-12-16T16:44:35.061020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train[1]","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:44:44.624215Z","iopub.execute_input":"2022-12-16T16:44:44.624674Z","iopub.status.idle":"2022-12-16T16:44:44.633903Z","shell.execute_reply.started":"2022-12-16T16:44:44.624637Z","shell.execute_reply":"2022-12-16T16:44:44.632306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_son = np.ones(y_train.shape, dtype=\"uint8\")\ny_train_son","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:45:20.855740Z","iopub.execute_input":"2022-12-16T16:45:20.856188Z","iopub.status.idle":"2022-12-16T16:45:20.862853Z","shell.execute_reply.started":"2022-12-16T16:45:20.856154Z","shell.execute_reply":"2022-12-16T16:45:20.861418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_son[:,4] =y_train[:,4]\ny_train_son","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:46:41.415429Z","iopub.execute_input":"2022-12-16T16:46:41.415886Z","iopub.status.idle":"2022-12-16T16:46:41.424301Z","shell.execute_reply.started":"2022-12-16T16:46:41.415852Z","shell.execute_reply":"2022-12-16T16:46:41.423060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"code","source":"import numpy as np\nnp.logical_or(0,0)  # False\nnp.logical_or(1,0)  # True\nnp.logical_or(0,1)  # True\nnp.logical_or(1,1)  # True\n\nnp.logical_and(0,1)  # False\nnp.logical_and(1,1)  # True\n","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:49:38.946799Z","iopub.execute_input":"2022-12-16T16:49:38.947304Z","iopub.status.idle":"2022-12-16T16:49:38.957682Z","shell.execute_reply.started":"2022-12-16T16:49:38.947265Z","shell.execute_reply":"2022-12-16T16:49:38.956052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(3,-1,-1):\n    y_train_son[:,i] = np.logical_or(y_train[:,i],y_train_son[:,i+1])","metadata":{"execution":{"iopub.status.busy":"2022-12-16T16:52:05.891716Z","iopub.execute_input":"2022-12-16T16:52:05.892158Z","iopub.status.idle":"2022-12-16T16:52:05.899574Z","shell.execute_reply.started":"2022-12-16T16:52:05.892124Z","shell.execute_reply":"2022-12-16T16:52:05.897831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}