{"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 os","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:36.626603Z","iopub.execute_input":"2023-10-30T06:07:36.627029Z","iopub.status.idle":"2023-10-30T06:07:37.112938Z","shell.execute_reply.started":"2023-10-30T06:07:36.626996Z","shell.execute_reply":"2023-10-30T06:07:37.111647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_dir = r'/kaggle/input/rsna-2022-cervical-spine-fracture-detection'\nprint(os.listdir(base_dir))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:41.281671Z","iopub.execute_input":"2023-10-30T06:07:41.282227Z","iopub.status.idle":"2023-10-30T06:07:41.289814Z","shell.execute_reply.started":"2023-10-30T06:07:41.282193Z","shell.execute_reply":"2023-10-30T06:07:41.288689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Read Training Data**","metadata":{}},{"cell_type":"code","source":"train_data = pd.read_csv(os.path.join(base_dir,\"train.csv\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:43.870032Z","iopub.execute_input":"2023-10-30T06:07:43.870492Z","iopub.status.idle":"2023-10-30T06:07:43.895252Z","shell.execute_reply.started":"2023-10-30T06:07:43.870456Z","shell.execute_reply":"2023-10-30T06:07:43.893992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Quick analysis on training data","metadata":{}},{"cell_type":"code","source":"train_data.info()\n#2019 records one for each study ids, no null values","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:44.609244Z","iopub.execute_input":"2023-10-30T06:07:44.609766Z","iopub.status.idle":"2023-10-30T06:07:44.65055Z","shell.execute_reply.started":"2023-10-30T06:07:44.609716Z","shell.execute_reply":"2023-10-30T06:07:44.649765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(1)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:47.834965Z","iopub.execute_input":"2023-10-30T06:07:47.836047Z","iopub.status.idle":"2023-10-30T06:07:47.850976Z","shell.execute_reply.started":"2023-10-30T06:07:47.835996Z","shell.execute_reply":"2023-10-30T06:07:47.849759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['patient_overall'].sum()/train_data.shape[0]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:48.142864Z","iopub.execute_input":"2023-10-30T06:07:48.143277Z","iopub.status.idle":"2023-10-30T06:07:48.15261Z","shell.execute_reply.started":"2023-10-30T06:07:48.143245Z","shell.execute_reply":"2023-10-30T06:07:48.151186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = train_data.iloc[:,1:].columns\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:48.384825Z","iopub.execute_input":"2023-10-30T06:07:48.386094Z","iopub.status.idle":"2023-10-30T06:07:48.395588Z","shell.execute_reply.started":"2023-10-30T06:07:48.38604Z","shell.execute_reply":"2023-10-30T06:07:48.394334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fracture_proportion = {col:(train_data[col].sum()/train_data.shape[0])*100 for col in columns}","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:48.624552Z","iopub.execute_input":"2023-10-30T06:07:48.62497Z","iopub.status.idle":"2023-10-30T06:07:48.631246Z","shell.execute_reply.started":"2023-10-30T06:07:48.624938Z","shell.execute_reply":"2023-10-30T06:07:48.630446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fracture_proportion['no_fractures'] = 100 - fracture_proportion['patient_overall']","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:52.833807Z","iopub.execute_input":"2023-10-30T06:07:52.834269Z","iopub.status.idle":"2023-10-30T06:07:52.839888Z","shell.execute_reply.started":"2023-10-30T06:07:52.834234Z","shell.execute_reply":"2023-10-30T06:07:52.838751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fracture proportion","metadata":{}},{"cell_type":"code","source":"fracture_proportion","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:53.323563Z","iopub.execute_input":"2023-10-30T06:07:53.324034Z","iopub.status.idle":"2023-10-30T06:07:53.332842Z","shell.execute_reply.started":"2023-10-30T06:07:53.324001Z","shell.execute_reply":"2023-10-30T06:07:53.331505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nlen(train_data.StudyInstanceUID.unique())","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:53.522217Z","iopub.execute_input":"2023-10-30T06:07:53.522641Z","iopub.status.idle":"2023-10-30T06:07:53.530013Z","shell.execute_reply.started":"2023-10-30T06:07:53.522608Z","shell.execute_reply":"2023-10-30T06:07:53.529123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum().sum()\n#No nulls","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:53.721638Z","iopub.execute_input":"2023-10-30T06:07:53.722083Z","iopub.status.idle":"2023-10-30T06:07:53.730846Z","shell.execute_reply.started":"2023-10-30T06:07:53.722049Z","shell.execute_reply":"2023-10-30T06:07:53.729755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_ids = list(train_data['StudyInstanceUID'].unique())","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:53.916458Z","iopub.execute_input":"2023-10-30T06:07:53.91783Z","iopub.status.idle":"2023-10-30T06:07:53.922553Z","shell.execute_reply.started":"2023-10-30T06:07:53.917794Z","shell.execute_reply":"2023-10-30T06:07:53.921776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_studyids = os.listdir(os.path.join(base_dir,'train_images'))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:54.096219Z","iopub.execute_input":"2023-10-30T06:07:54.09704Z","iopub.status.idle":"2023-10-30T06:07:54.159753Z","shell.execute_reply.started":"2023-10-30T06:07:54.096995Z","shell.execute_reply":"2023-10-30T06:07:54.158533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_image_studyids)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:54.293692Z","iopub.execute_input":"2023-10-30T06:07:54.294151Z","iopub.status.idle":"2023-10-30T06:07:54.301891Z","shell.execute_reply.started":"2023-10-30T06:07:54.294118Z","shell.execute_reply":"2023-10-30T06:07:54.300749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_train_images = [id for id in train_study_ids if id not in train_image_studyids]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:54.480423Z","iopub.execute_input":"2023-10-30T06:07:54.480823Z","iopub.status.idle":"2023-10-30T06:07:54.548781Z","shell.execute_reply.started":"2023-10-30T06:07:54.480793Z","shell.execute_reply":"2023-10-30T06:07:54.547617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_train_images\n#Every study id in the train data has a training image","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:54.708658Z","iopub.execute_input":"2023-10-30T06:07:54.709071Z","iopub.status.idle":"2023-10-30T06:07:54.716611Z","shell.execute_reply.started":"2023-10-30T06:07:54.709039Z","shell.execute_reply":"2023-10-30T06:07:54.715222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Summary of training data\n1. There are 2019 patients (study ids) available in the training data\n2. All the 2019 patients have training images\n3. 47% of the patients have fractures\n4. The fracture counts are in the order of C7,C2,C6,C5,C1,C4,C3  \n5. All the training images are in DICOM format. \n6. Each patient has multiple slices of CT scans taken from different views\n7. All the images are in Saggital View\n","metadata":{}},{"cell_type":"code","source":"#test_image_studyids = os.listdir(os.path.join(base_dir,'test_images'))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:55.121558Z","iopub.execute_input":"2023-10-30T06:07:55.122054Z","iopub.status.idle":"2023-10-30T06:07:55.127137Z","shell.execute_reply.started":"2023-10-30T06:07:55.12202Z","shell.execute_reply":"2023-10-30T06:07:55.126235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Segmentation data analysis","metadata":{}},{"cell_type":"code","source":"segmentations = os.path.join(base_dir,'segmentations')\nsegmentation_ids = [id[:-4] for id in os.listdir(segmentations)]\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:55.549103Z","iopub.execute_input":"2023-10-30T06:07:55.549464Z","iopub.status.idle":"2023-10-30T06:07:55.571312Z","shell.execute_reply.started":"2023-10-30T06:07:55.549435Z","shell.execute_reply":"2023-10-30T06:07:55.570369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(segmentation_ids)\n#Only 87 studyids have segmentation data","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:55.782935Z","iopub.execute_input":"2023-10-30T06:07:55.783348Z","iopub.status.idle":"2023-10-30T06:07:55.794966Z","shell.execute_reply.started":"2023-10-30T06:07:55.783318Z","shell.execute_reply":"2023-10-30T06:07:55.793845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segmentation_ids.sort()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:07:56.081007Z","iopub.execute_input":"2023-10-30T06:07:56.081486Z","iopub.status.idle":"2023-10-30T06:07:56.087217Z","shell.execute_reply.started":"2023-10-30T06:07:56.081451Z","shell.execute_reply":"2023-10-30T06:07:56.086079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segmentation_ids","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:00.275936Z","iopub.execute_input":"2023-10-30T06:08:00.276312Z","iopub.status.idle":"2023-10-30T06:08:00.285126Z","shell.execute_reply.started":"2023-10-30T06:08:00.276283Z","shell.execute_reply":"2023-10-30T06:08:00.283939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_segmentation_ids = [id for id in segmentation_ids if id in train_study_ids]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:00.589994Z","iopub.execute_input":"2023-10-30T06:08:00.590383Z","iopub.status.idle":"2023-10-30T06:08:00.598578Z","shell.execute_reply.started":"2023-10-30T06:08:00.590352Z","shell.execute_reply":"2023-10-30T06:08:00.597451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_segmentation_ids)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:05.41743Z","iopub.execute_input":"2023-10-30T06:08:05.418201Z","iopub.status.idle":"2023-10-30T06:08:05.425751Z","shell.execute_reply.started":"2023-10-30T06:08:05.418168Z","shell.execute_reply":"2023-10-30T06:08:05.423681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images_segmentation_ids = [id for id in segmentation_ids if id in train_image_studyids]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:05.652884Z","iopub.execute_input":"2023-10-30T06:08:05.653263Z","iopub.status.idle":"2023-10-30T06:08:05.660754Z","shell.execute_reply.started":"2023-10-30T06:08:05.653235Z","shell.execute_reply":"2023-10-30T06:08:05.659531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_images_segmentation_ids)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:05.841524Z","iopub.execute_input":"2023-10-30T06:08:05.842083Z","iopub.status.idle":"2023-10-30T06:08:05.849133Z","shell.execute_reply.started":"2023-10-30T06:08:05.84205Z","shell.execute_reply":"2023-10-30T06:08:05.84809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"no_segmentation_ids = [id for id in train_study_ids if id not in segmentation_ids]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:06.017834Z","iopub.execute_input":"2023-10-30T06:08:06.01826Z","iopub.status.idle":"2023-10-30T06:08:06.028881Z","shell.execute_reply.started":"2023-10-30T06:08:06.018223Z","shell.execute_reply":"2023-10-30T06:08:06.02779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(no_segmentation_ids)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:06.211281Z","iopub.execute_input":"2023-10-30T06:08:06.21166Z","iopub.status.idle":"2023-10-30T06:08:06.218451Z","shell.execute_reply.started":"2023-10-30T06:08:06.211631Z","shell.execute_reply":"2023-10-30T06:08:06.217183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Summary of segmentation data\n1. 87 out of 2019 patients have segmentation data\n2. All the segmentation data is available in NIBABEL format\n3. According to compeitition description, segmentation Images are in Axial Plane. Hence, it is important to convert these images to Saggital plane to compare it with the DICOM data\n4. Each slice in the segmentation 3D image represents the bone. Hence this information can be useful to understand which bone the respective DICOM image is representing\n5. 1932 patients doesn't have any segmentation images.","metadata":{}},{"cell_type":"markdown","source":"# Training bounding boxes analysis","metadata":{}},{"cell_type":"code","source":"train_bounding_boxes = pd.read_csv(os.path.join(base_dir,\"train_bounding_boxes.csv\"))","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:11.745853Z","iopub.execute_input":"2023-10-30T06:08:11.746225Z","iopub.status.idle":"2023-10-30T06:08:11.77979Z","shell.execute_reply.started":"2023-10-30T06:08:11.746196Z","shell.execute_reply":"2023-10-30T06:08:11.778428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_bounding_boxes.info()","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:11.971046Z","iopub.execute_input":"2023-10-30T06:08:11.971502Z","iopub.status.idle":"2023-10-30T06:08:11.987504Z","shell.execute_reply.started":"2023-10-30T06:08:11.971467Z","shell.execute_reply":"2023-10-30T06:08:11.98622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_bounding_boxes.head(1)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:12.155135Z","iopub.execute_input":"2023-10-30T06:08:12.155528Z","iopub.status.idle":"2023-10-30T06:08:12.170351Z","shell.execute_reply.started":"2023-10-30T06:08:12.155498Z","shell.execute_reply":"2023-10-30T06:08:12.16899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_bounding_box_ids = list(train_bounding_boxes['StudyInstanceUID'].unique())","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:12.35367Z","iopub.execute_input":"2023-10-30T06:08:12.354129Z","iopub.status.idle":"2023-10-30T06:08:12.361176Z","shell.execute_reply.started":"2023-10-30T06:08:12.354096Z","shell.execute_reply":"2023-10-30T06:08:12.359858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_bounding_box_ids)\n#there are 235 unique study ids in bounding boxes data","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:12.53388Z","iopub.execute_input":"2023-10-30T06:08:12.534327Z","iopub.status.idle":"2023-10-30T06:08:12.542023Z","shell.execute_reply.started":"2023-10-30T06:08:12.534295Z","shell.execute_reply":"2023-10-30T06:08:12.540522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Get total slice count or each patient \nstudy_slices = train_bounding_boxes.groupby(['StudyInstanceUID'])['slice_number'].count().reset_index().sort_values(by='slice_number',ascending=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:12.665786Z","iopub.execute_input":"2023-10-30T06:08:12.666199Z","iopub.status.idle":"2023-10-30T06:08:12.677208Z","shell.execute_reply.started":"2023-10-30T06:08:12.666169Z","shell.execute_reply":"2023-10-30T06:08:12.67562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"study_slices = study_slices.reset_index(drop=True).rename(columns={'slice_number':'total_slice_count'})","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:12.836183Z","iopub.execute_input":"2023-10-30T06:08:12.836639Z","iopub.status.idle":"2023-10-30T06:08:12.845184Z","shell.execute_reply.started":"2023-10-30T06:08:12.836605Z","shell.execute_reply":"2023-10-30T06:08:12.843789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"study_slices","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:13.243772Z","iopub.execute_input":"2023-10-30T06:08:13.244226Z","iopub.status.idle":"2023-10-30T06:08:13.259453Z","shell.execute_reply.started":"2023-10-30T06:08:13.244193Z","shell.execute_reply":"2023-10-30T06:08:13.258111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Get list of ids who have both segmentation image and training bounding box id\ntrain_seg_bounding_boxes_ids = [id for id in train_segmentation_ids if id in train_bounding_box_ids]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:13.445674Z","iopub.execute_input":"2023-10-30T06:08:13.446138Z","iopub.status.idle":"2023-10-30T06:08:13.452292Z","shell.execute_reply.started":"2023-10-30T06:08:13.446103Z","shell.execute_reply":"2023-10-30T06:08:13.451003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_seg_bounding_boxes_ids) # these are the ids with train image, segmentation value and bounding box values. Pick one with highest slices","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:14.014224Z","iopub.execute_input":"2023-10-30T06:08:14.014671Z","iopub.status.idle":"2023-10-30T06:08:14.023088Z","shell.execute_reply.started":"2023-10-30T06:08:14.014632Z","shell.execute_reply":"2023-10-30T06:08:14.02169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"study_slices[study_slices['StudyInstanceUID'].isin(train_seg_bounding_boxes_ids)]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:14.343894Z","iopub.execute_input":"2023-10-30T06:08:14.344267Z","iopub.status.idle":"2023-10-30T06:08:14.360077Z","shell.execute_reply.started":"2023-10-30T06:08:14.344238Z","shell.execute_reply":"2023-10-30T06:08:14.358778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pick index 234 - the one with less slices\n#1.2.826.0.1.3680043.780 -> 2 slices\n","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:15.23609Z","iopub.execute_input":"2023-10-30T06:08:15.236545Z","iopub.status.idle":"2023-10-30T06:08:15.243114Z","shell.execute_reply.started":"2023-10-30T06:08:15.236513Z","shell.execute_reply":"2023-10-30T06:08:15.241679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pick study instance id with minimal slice count to quickly check the data\ntrain_bounding_boxes[train_bounding_boxes['StudyInstanceUID']=='1.2.826.0.1.3680043.780']","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:15.986564Z","iopub.execute_input":"2023-10-30T06:08:15.987531Z","iopub.status.idle":"2023-10-30T06:08:16.003783Z","shell.execute_reply.started":"2023-10-30T06:08:15.987481Z","shell.execute_reply":"2023-10-30T06:08:16.002298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Visualize this study ID both dicom, NITII images","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:19.724179Z","iopub.execute_input":"2023-10-30T06:08:19.724548Z","iopub.status.idle":"2023-10-30T06:08:19.729598Z","shell.execute_reply.started":"2023-10-30T06:08:19.72452Z","shell.execute_reply":"2023-10-30T06:08:19.728165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Get list of ids who have bounding boxes but no segmentation images\ntrain_data_boxes_id = [id for id in train_study_ids if (id in train_bounding_box_ids and id not in train_segmentation_ids)]","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:20.720633Z","iopub.execute_input":"2023-10-30T06:08:20.721081Z","iopub.status.idle":"2023-10-30T06:08:20.740284Z","shell.execute_reply.started":"2023-10-30T06:08:20.721032Z","shell.execute_reply":"2023-10-30T06:08:20.739102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_data_boxes_id)","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:22.295792Z","iopub.execute_input":"2023-10-30T06:08:22.296213Z","iopub.status.idle":"2023-10-30T06:08:22.303607Z","shell.execute_reply.started":"2023-10-30T06:08:22.296182Z","shell.execute_reply":"2023-10-30T06:08:22.302096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Summary of bounding box Data\n1. For 235 patitents the bounding box data is available. \n2. Only 40 patients have CT scan image, segmentation image and its respective bounding box data\n3. However, the bounding box data is not available for all the CT scan images of the 40 patients above. Few patients have bounding box data available only for 2 slices\n4. Rest of the 195 patients have CT scan images and bounding box data but no individual segmentation image data\n5. 47 patients who have segmentation images doesn't have training bounding box data","metadata":{}},{"cell_type":"code","source":"#EDA code Inspired from https://www.kaggle.com/code/samuelcortinhas/rsna-fracture-detection-in-depth-eda\n\n\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport matplotlib.patches as patches\nimport seaborn as sns\nsns.set(style='darkgrid', font_scale=1.6)\n\nimport warnings\n\n\nplt.figure(figsize=(20,6))\nplt.subplot(1,2,1)\nax1 = sns.countplot(data=train_data, x='patient_overall')\nfor container in ax1.containers:\n    ax1.bar_label(container)\nplt.title('Fractures by patient')\nplt.ylim([0,1300])\n\n# Unpivot train_df for plotting\ntrain_melt = pd.melt(train_data, id_vars = ['StudyInstanceUID', 'patient_overall'],\n             value_vars = ['C1','C2','C3','C4','C5','C6','C7'],\n             var_name=\"Vertebrae\",\n             value_name=\"Fractured\")\n\nplt.subplot(1,2,2)\nax2 = sns.countplot(data=train_melt, x='Vertebrae', hue='Fractured')\nfor container in ax2.containers:\n    ax2.bar_label(container)\nplt.title('Fractures by vertebrae')","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:08:52.655745Z","iopub.execute_input":"2023-10-30T06:08:52.656165Z","iopub.status.idle":"2023-10-30T06:08:53.573211Z","shell.execute_reply.started":"2023-10-30T06:08:52.656133Z","shell.execute_reply":"2023-10-30T06:08:53.572357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,5))\nax = sns.countplot(x = train_data[['C1','C2','C3','C4','C5','C6','C7']].sum(axis=1))\nfor container in ax.containers:\n    ax.bar_label(container)\nplt.title('Number of fractures by patient')\nplt.xlabel('Number of fractures')\nplt.ylim([0,1300])","metadata":{"execution":{"iopub.status.busy":"2023-10-30T06:09:06.113819Z","iopub.execute_input":"2023-10-30T06:09:06.11539Z","iopub.status.idle":"2023-10-30T06:09:06.590332Z","shell.execute_reply.started":"2023-10-30T06:09:06.115326Z","shell.execute_reply":"2023-10-30T06:09:06.58902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Next steps\nIn the next notebook, I will pick one study id which have both segmentation data and training box id and map it with its respective DICOM CT scan image to see all of them together.\nhttps://www.kaggle.com/code/saikiranvarma/visualizing-segmented-train-image\n","metadata":{}}]}