{"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":"markdown","source":"# Let's try looking at images **on our eyes** and searching cancers.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom pathlib import Path\nimport glob\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:30:51.135984Z","iopub.execute_input":"2022-12-23T00:30:51.136605Z","iopub.status.idle":"2022-12-23T00:30:51.960343Z","shell.execute_reply.started":"2022-12-23T00:30:51.13648Z","shell.execute_reply":"2022-12-23T00:30:51.959154Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/rsna-breast-cancer-detection/train.csv')\ndf0 = train_df[train_df.cancer==0]\ndf1 = train_df[train_df.cancer==1]\ndisplay(df0)\ndisplay(df1)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-23T00:30:51.962594Z","iopub.execute_input":"2022-12-23T00:30:51.963669Z","iopub.status.idle":"2022-12-23T00:30:52.183399Z","shell.execute_reply.started":"2022-12-23T00:30:51.963624Z","shell.execute_reply":"2022-12-23T00:30:52.18189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\nimg_ids0 = list(df0.image_id)\nimg_ids1 = list(df1.image_id)\nrandom.seed(0)\nrandom.shuffle(img_ids0)\nrandom.shuffle(img_ids1)\n\nlen(img_ids0),len(img_ids1)","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:30:52.185252Z","iopub.execute_input":"2022-12-23T00:30:52.185812Z","iopub.status.idle":"2022-12-23T00:30:52.276036Z","shell.execute_reply.started":"2022-12-23T00:30:52.185774Z","shell.execute_reply":"2022-12-23T00:30:52.274065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_images_for_image_ids(image_ids,figsize=(48,30),suptitle=None):\n    root_dir = '/kaggle/input/rsna-breast-cancer-1024-pngs/output'\n    fig, axs = plt.subplots(int((len(image_ids)+1)/2),2,figsize=figsize)\n    if suptitle: fig.suptitle(f'{suptitle}', fontsize=16)\n    axs = axs.flatten()\n    for i, image_id in enumerate(image_ids):\n        img = Image.open(glob.glob(f\"{root_dir}/*_{image_id}.png\")[0])\n        axs[i].imshow(img, cmap=\"bone\")\n        axs[i].set_title(f'image_id: {image_id}')\n","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:30:52.27906Z","iopub.execute_input":"2022-12-23T00:30:52.279545Z","iopub.status.idle":"2022-12-23T00:30:52.288762Z","shell.execute_reply.started":"2022-12-23T00:30:52.279501Z","shell.execute_reply":"2022-12-23T00:30:52.287216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 10 Positive Examples","metadata":{}},{"cell_type":"code","source":"show_images_for_image_ids(img_ids1[0:10],figsize=(20,50),suptitle='positive examples')","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:31:43.913213Z","iopub.execute_input":"2022-12-23T00:31:43.913741Z","iopub.status.idle":"2022-12-23T00:31:48.825439Z","shell.execute_reply.started":"2022-12-23T00:31:43.913691Z","shell.execute_reply":"2022-12-23T00:31:48.823179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 10 Negative Examples","metadata":{}},{"cell_type":"code","source":"show_images_for_image_ids(img_ids0[0:10],figsize=(20,50),suptitle='negative examples')","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:31:48.828032Z","iopub.execute_input":"2022-12-23T00:31:48.828602Z","iopub.status.idle":"2022-12-23T00:31:53.884806Z","shell.execute_reply.started":"2022-12-23T00:31:48.828556Z","shell.execute_reply":"2022-12-23T00:31:53.883006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# create positive ","metadata":{}},{"cell_type":"code","source":"imgID_to_patientID_dict = {\n    image_id:int(train_df[train_df.image_id==image_id].patient_id) for image_id in list(train_df.image_id)\n}\nimgID_to_patientID_dict[1234933874]","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:52:13.699973Z","iopub.execute_input":"2022-12-23T00:52:13.700459Z","iopub.status.idle":"2022-12-23T00:52:46.880652Z","shell.execute_reply.started":"2022-12-23T00:52:13.700424Z","shell.execute_reply":"2022-12-23T00:52:46.879199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport cv2\n\nroot_dir = '/kaggle/input/rsna-breast-cancer-1024-pngs/output'\nimage_ids = img_ids0\nfor i, image_id in (enumerate(image_ids)):\n    img = cv2.imread(glob.glob(f\"{root_dir}/{imgID_to_patientID_dict[image_id]}_{image_id}.png\")[0])\n    cv2.imwrite(f'{imgID_to_patientID_dict[image_id]}_{image_id}.png', img)","metadata":{"execution":{"iopub.status.busy":"2022-12-23T00:55:05.776445Z","iopub.execute_input":"2022-12-23T00:55:05.776961Z","iopub.status.idle":"2022-12-23T00:58:57.915719Z","shell.execute_reply.started":"2022-12-23T00:55:05.776923Z","shell.execute_reply":"2022-12-23T00:58:57.914059Z"},"trusted":true},"execution_count":null,"outputs":[]}]}