{"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":"# Ovarian Image Appearance by Label","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport os\nimport matplotlib.pyplot as plt\nimport cv2\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-07T07:57:25.512701Z","iopub.execute_input":"2023-10-07T07:57:25.51378Z","iopub.status.idle":"2023-10-07T07:57:25.52048Z","shell.execute_reply.started":"2023-10-07T07:57:25.513746Z","shell.execute_reply":"2023-10-07T07:57:25.519596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img=plt.imread('/kaggle/input/UBC-OCEAN/train_thumbnails/10077_thumbnail.png')\nplt.figure(figsize=(8,8))\nplt.imshow(img)\nplt.show()\nprint(img.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T07:57:25.522209Z","iopub.execute_input":"2023-10-07T07:57:25.522774Z","iopub.status.idle":"2023-10-07T07:57:27.447632Z","shell.execute_reply.started":"2023-10-07T07:57:25.522742Z","shell.execute_reply":"2023-10-07T07:57:27.446681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv('/kaggle/input/UBC-OCEAN/train.csv')\ndisplay(train[train['image_id']==10077])","metadata":{"execution":{"iopub.status.busy":"2023-10-07T07:57:27.44911Z","iopub.execute_input":"2023-10-07T07:57:27.449495Z","iopub.status.idle":"2023-10-07T07:57:27.469127Z","shell.execute_reply.started":"2023-10-07T07:57:27.449462Z","shell.execute_reply":"2023-10-07T07:57:27.468022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tma_true=train[train['is_tma']==True]['image_id'].tolist()\ntma_false=train[train['is_tma']==False]['image_id'].tolist()\n\ntrain_id=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/UBC-OCEAN/train_thumbnails'):\n    for filename in filenames:\n        train_id+=[int(filename.split('_')[0])]\n\nprint(set(train_id)&set(tma_false))\n\nprint(set(train_id)&set(tma_true))\n#image ids of tma true are in train.csv but not in image folder.","metadata":{"execution":{"iopub.status.busy":"2023-10-07T07:57:27.494398Z","iopub.execute_input":"2023-10-07T07:57:27.49497Z","iopub.status.idle":"2023-10-07T07:57:27.506599Z","shell.execute_reply.started":"2023-10-07T07:57:27.494913Z","shell.execute_reply":"2023-10-07T07:57:27.505726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train2=train[train['is_tma']==False]\nprint(train['label'].unique().tolist())\n\nimage_ids=[]\nfor label_value in train['label'].unique().tolist():\n    selected_ids = []\n    label_subset = train2[train2['label'] == label_value]\n    selected_subset = label_subset.sample(min(8, len(label_subset)))\n    image_ids+=[selected_subset['image_id'].tolist()]\nprint(image_ids)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T08:01:04.903271Z","iopub.execute_input":"2023-10-07T08:01:04.903709Z","iopub.status.idle":"2023-10-07T08:01:04.919284Z","shell.execute_reply.started":"2023-10-07T08:01:04.903679Z","shell.execute_reply":"2023-10-07T08:01:04.91749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Abbrebiation\n\nHGSC (High-Grade Serous Carcinoma): HGSC is the most common subtype of ovarian cancer and is characterized by high malignancy. This subtype usually arises from the epithelial cells of the ovary and can be aggressive and difficult to treat.\n\nLGSC (Low-Grade Serous Carcinoma): In contrast to HGSC, LGSC is a subtype with low malignant potential. This subtype also arises from the epithelial cells of the ovary, but is slow to progress and generally has a good prognosis.\n\nEC (Endometrioid Carcinoma): EC is a subtype of ovarian cancer that originates from cancer cells that originate from the endometrium. This type is usually associated with estrogen-related risk factors.\n\nCC (Clear Cell Carcinoma): CC is a subtype of ovarian cancer that is made up of characteristic cancer cells called clear cells. This subtype is uncommon and has a generally poor prognosis.\n\nMC (Mucinous Carcinoma): MC is a type of ovarian cancer that is made up of mucus-producing cells. This subtype is also uncommon and has characteristics that differ from other ovarian cancers.","metadata":{}},{"cell_type":"markdown","source":"# Ovrian Image Appearance by Label\nFocus of lesion unknown","metadata":{}},{"cell_type":"code","source":"dir0='/kaggle/input/UBC-OCEAN/train_thumbnails'\nfilebottom='_thumbnail.png'\nfor i,label in enumerate(train['label'].unique().tolist()):\n    fig, axs = plt.subplots(1, 4, figsize=(12,3))\n    ids=image_ids[i]\n    print(label)\n    for j,idi in enumerate(ids[0:4]):\n        path=os.path.join(dir0,str(idi)+filebottom)\n        #print(path)\n        img=cv2.imread(path)\n        img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)\n        axs[j].imshow(img)\n        axs[j].axis(\"off\")\n    plt.tight_layout()\n    plt.show()\n    print()\n    ","metadata":{"execution":{"iopub.status.busy":"2023-10-07T08:44:05.163534Z","iopub.execute_input":"2023-10-07T08:44:05.164465Z","iopub.status.idle":"2023-10-07T08:44:22.833868Z","shell.execute_reply.started":"2023-10-07T08:44:05.164429Z","shell.execute_reply":"2023-10-07T08:44:22.832695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}