{"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":"EDA Focused on Segmentations and bounding box annotations","metadata":{"execution":{"iopub.status.busy":"2022-07-29T07:11:03.457277Z"}}},{"cell_type":"code","source":"# source: https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\n!pip install -q ../input/for-pydicom/pylibjpeg-1.4.0-py3-none-any.whl\n!pip install -q ../input/for-pydicom/python_gdcm-3.0.14-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\n!pip install -q ../input/for-pydicom/pylibjpeg_libjpeg-1.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:53:47.141054Z","iopub.execute_input":"2022-07-31T17:53:47.141454Z","iopub.status.idle":"2022-07-31T17:55:27.325374Z","shell.execute_reply.started":"2022-07-31T17:53:47.141423Z","shell.execute_reply":"2022-07-31T17:55:27.32385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport matplotlib.pyplot as plt \n\nfrom path import Path\nimport os \nimport glob\n\nimport os ","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.327759Z","iopub.execute_input":"2022-07-31T17:55:27.328146Z","iopub.status.idle":"2022-07-31T17:55:27.347479Z","shell.execute_reply.started":"2022-07-31T17:55:27.328111Z","shell.execute_reply":"2022-07-31T17:55:27.346562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/rsna-2022-cervical-spine-fracture-detection/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.352116Z","iopub.execute_input":"2022-07-31T17:55:27.35294Z","iopub.status.idle":"2022-07-31T17:55:27.375467Z","shell.execute_reply.started":"2022-07-31T17:55:27.352899Z","shell.execute_reply":"2022-07-31T17:55:27.374555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[\"count\"] = 1\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.377964Z","iopub.execute_input":"2022-07-31T17:55:27.378573Z","iopub.status.idle":"2022-07-31T17:55:27.417195Z","shell.execute_reply.started":"2022-07-31T17:55:27.378537Z","shell.execute_reply":"2022-07-31T17:55:27.416417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_cols = train_df.columns[1:]","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.418498Z","iopub.execute_input":"2022-07-31T17:55:27.418854Z","iopub.status.idle":"2022-07-31T17:55:27.423638Z","shell.execute_reply.started":"2022-07-31T17:55:27.418827Z","shell.execute_reply":"2022-07-31T17:55:27.422642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Segmentations","metadata":{}},{"cell_type":"code","source":"segmentations_paths = list(Path(\"../input/rsna-2022-cervical-spine-fracture-detection/segmentations\").glob(\"*.nii\"))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.425004Z","iopub.execute_input":"2022-07-31T17:55:27.425399Z","iopub.status.idle":"2022-07-31T17:55:27.463873Z","shell.execute_reply.started":"2022-07-31T17:55:27.425369Z","shell.execute_reply":"2022-07-31T17:55:27.46266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients_with_seg = [p.stem for p in segmentations_paths]\nlen(patients_with_seg)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.467575Z","iopub.execute_input":"2022-07-31T17:55:27.468437Z","iopub.status.idle":"2022-07-31T17:55:27.477894Z","shell.execute_reply.started":"2022-07-31T17:55:27.468392Z","shell.execute_reply":"2022-07-31T17:55:27.476663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(set(train_df['StudyInstanceUID'].values) & set(patients_with_seg))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.48205Z","iopub.execute_input":"2022-07-31T17:55:27.482763Z","iopub.status.idle":"2022-07-31T17:55:27.492963Z","shell.execute_reply.started":"2022-07-31T17:55:27.482717Z","shell.execute_reply":"2022-07-31T17:55:27.491921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Bounding boxes","metadata":{}},{"cell_type":"code","source":"bounding_boxes = pd.read_csv(\"../input/rsna-2022-cervical-spine-fracture-detection/train_bounding_boxes.csv\")\nbounding_boxes.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.494315Z","iopub.execute_input":"2022-07-31T17:55:27.495103Z","iopub.status.idle":"2022-07-31T17:55:27.522577Z","shell.execute_reply.started":"2022-07-31T17:55:27.495071Z","shell.execute_reply":"2022-07-31T17:55:27.521484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients_with_bbox = set(bounding_boxes['StudyInstanceUID'])\nlen(patients_with_bbox)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.528178Z","iopub.execute_input":"2022-07-31T17:55:27.528558Z","iopub.status.idle":"2022-07-31T17:55:27.53791Z","shell.execute_reply.started":"2022-07-31T17:55:27.528523Z","shell.execute_reply":"2022-07-31T17:55:27.536643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(set(patients_with_bbox) & set(patients_with_seg))","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.539589Z","iopub.execute_input":"2022-07-31T17:55:27.540228Z","iopub.status.idle":"2022-07-31T17:55:27.546301Z","shell.execute_reply.started":"2022-07-31T17:55:27.540193Z","shell.execute_reply":"2022-07-31T17:55:27.545621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# only 40 patients with seg have bounding box for a fracture. Why? just 40 of them have any fracture.","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.547678Z","iopub.execute_input":"2022-07-31T17:55:27.548201Z","iopub.status.idle":"2022-07-31T17:55:27.556058Z","shell.execute_reply.started":"2022-07-31T17:55:27.548172Z","shell.execute_reply":"2022-07-31T17:55:27.555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Are segmentations & bboxes available for a representative sample?","metadata":{}},{"cell_type":"code","source":"dfs = {\n    \"all\": train_df,\n    \"seg\": train_df[train_df['StudyInstanceUID'].isin(patients_with_seg)],\n    \"bbox\": train_df[train_df['StudyInstanceUID'].isin(patients_with_bbox)],\n}\n\nfig, axis = plt.subplot_mosaic([dfs.keys()], figsize=(20,8))\nfor name ,ax in axis.items():\n    dfs[name][val_cols].sum().plot.bar(ax=ax)\n    ax.set_title(name)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:27.557516Z","iopub.execute_input":"2022-07-31T17:55:27.560391Z","iopub.status.idle":"2022-07-31T17:55:28.122001Z","shell.execute_reply.started":"2022-07-31T17:55:27.560342Z","shell.execute_reply":"2022-07-31T17:55:28.120982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- distributions of fracture prevalence in general dataset and covered by segmentations is similar, with some classes over-represented in segmentations (C3, C4)\n- no no-fracture patients with bbox (that is fine, since we should just have bboxes of the fractures)\n- distributions of vertebrae fracture prevalence in general dataset and covered by bbox is similar","metadata":{}},{"cell_type":"markdown","source":"# Bounding boxes","metadata":{}},{"cell_type":"markdown","source":"We will calculate the extent of a bboxes for single instance, but taking a diff of max and min of slice_number and compare that to no of defined slices to look for non-continuity","metadata":{}},{"cell_type":"code","source":"bounding_boxes_gb = bounding_boxes.groupby('StudyInstanceUID').agg({'slice_number':['min','max','count']})\nbounding_boxes_gb.columns = bounding_boxes_gb.columns.droplevel()\nbounding_boxes_gb['extent'] = bounding_boxes_gb['max'] - bounding_boxes_gb['min'] + 1\nbounding_boxes_gb","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.123271Z","iopub.execute_input":"2022-07-31T17:55:28.123605Z","iopub.status.idle":"2022-07-31T17:55:28.148336Z","shell.execute_reply.started":"2022-07-31T17:55:28.123561Z","shell.execute_reply":"2022-07-31T17:55:28.147063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# no bounding boxes with errors \nsum(bounding_boxes_gb['extent'] < bounding_boxes_gb['count'])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.149919Z","iopub.execute_input":"2022-07-31T17:55:28.150244Z","iopub.status.idle":"2022-07-31T17:55:28.157844Z","shell.execute_reply.started":"2022-07-31T17:55:28.150214Z","shell.execute_reply":"2022-07-31T17:55:28.156751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multiple_boxes_mask = (bounding_boxes_gb['extent'] > bounding_boxes_gb['count'])\nsum(multiple_boxes_mask)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.159777Z","iopub.execute_input":"2022-07-31T17:55:28.160535Z","iopub.status.idle":"2022-07-31T17:55:28.172215Z","shell.execute_reply.started":"2022-07-31T17:55:28.160493Z","shell.execute_reply":"2022-07-31T17:55:28.171296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_boxes_gb[multiple_boxes_mask].sort_values('count')","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.173666Z","iopub.execute_input":"2022-07-31T17:55:28.174716Z","iopub.status.idle":"2022-07-31T17:55:28.190483Z","shell.execute_reply.started":"2022-07-31T17:55:28.174667Z","shell.execute_reply":"2022-07-31T17:55:28.189657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients_bbox_to_debug = bounding_boxes_gb[multiple_boxes_mask].sort_values('count').index.values[:2]\npatients_bbox_to_debug","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.192036Z","iopub.execute_input":"2022-07-31T17:55:28.192693Z","iopub.status.idle":"2022-07-31T17:55:28.200675Z","shell.execute_reply.started":"2022-07-31T17:55:28.192658Z","shell.execute_reply":"2022-07-31T17:55:28.199818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_boxes[bounding_boxes['StudyInstanceUID'].isin(patients_bbox_to_debug)].sort_values(['StudyInstanceUID', 'slice_number'])","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.202306Z","iopub.execute_input":"2022-07-31T17:55:28.202934Z","iopub.status.idle":"2022-07-31T17:55:28.225943Z","shell.execute_reply.started":"2022-07-31T17:55:28.2029Z","shell.execute_reply":"2022-07-31T17:55:28.225045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# to observe segmentations as well:\nbounding_boxes_with_seg = bounding_boxes[bounding_boxes['StudyInstanceUID'].isin(patients_with_seg)]\nbounding_boxes_with_seg","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.227493Z","iopub.execute_input":"2022-07-31T17:55:28.228121Z","iopub.status.idle":"2022-07-31T17:55:28.249482Z","shell.execute_reply.started":"2022-07-31T17:55:28.228087Z","shell.execute_reply":"2022-07-31T17:55:28.248642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# one can see that slices in bbox are in 2D and do not necessarily form a continuous structure.\n#1st patient above have slices 195 & 196 missing, while the second have a gap of ~30 slices, which well may be covering another C*\n","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.25104Z","iopub.execute_input":"2022-07-31T17:55:28.251623Z","iopub.status.idle":"2022-07-31T17:55:28.255695Z","shell.execute_reply.started":"2022-07-31T17:55:28.251576Z","shell.execute_reply":"2022-07-31T17:55:28.254576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Used notebook https://www.kaggle.com/code/muki2003/display-dicom-and-nifti-format-s","metadata":{}},{"cell_type":"code","source":"import cv2\nimport PIL\nimport pydicom as dicom\nimport nibabel as nib\nimport matplotlib.patches as patches","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.257424Z","iopub.execute_input":"2022-07-31T17:55:28.258059Z","iopub.status.idle":"2022-07-31T17:55:28.900407Z","shell.execute_reply.started":"2022-07-31T17:55:28.258026Z","shell.execute_reply":"2022-07-31T17:55:28.899097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from typing import Optional, Tuple\n\ndef load_case_data(patient_id) -> Tuple[np.ndarray, Optional[np.ndarray], Optional[pd.DataFrame]]:\n    \"\"\"\n    returns a tuple of image_data, vertebrae segmentation(optional), fracture bbox (optional) aligned to the coordinate system of the image\n    \"\"\"\n    patient_dir = Path(f\"../input/rsna-2022-cervical-spine-fracture-detection/train_images/{patient_id}\")\n    no_files = len(patient_dir.glob(\"*.dcm\"))\n    image_path = patient_dir / \"1.dcm\"\n    ds = dicom.dcmread(image_path)\n    \n    image = np.zeros((*ds.pixel_array.shape, no_files))\n    \n    for i in range(no_files):\n        image_path = patient_dir / f\"{i+1}.dcm\"\n    \n        image[:,:,i] = dicom.dcmread(image_path).pixel_array\n    \n    seg = None    \n    if patient_id in patients_with_seg:\n\n        patient_seg_path = Path(f\"../input/rsna-2022-cervical-spine-fracture-detection/segmentations/{patient_id}.nii\")\n        seg = nib.load(patient_seg_path).get_fdata()\n        # https://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/data\n        seg = np.flip(seg, axis=-1) # flip in Z\n        seg = np.rot90(seg) # rotate in XY \n        \n        assert seg.shape == image.shape\n    \n    bbox = None\n    \n    if patient_id in patients_with_bbox:\n        bbox = bounding_boxes[bounding_boxes['StudyInstanceUID'] == patient_id]\n        \n    return image, seg, bbox\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:28.902145Z","iopub.execute_input":"2022-07-31T17:55:28.90252Z","iopub.status.idle":"2022-07-31T17:55:28.915659Z","shell.execute_reply.started":"2022-07-31T17:55:28.902485Z","shell.execute_reply":"2022-07-31T17:55:28.914634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_patient(case_data, n=42, offset=0):\n    \n    img, seg, bboxes = case_data\n    \n    plt.figure(figsize=(20, 20))\n\n    # image with optionally shown bboxes:\n    for i in range(1, n+1):\n        ax = plt.subplot(7, 7, i)        \n        plt.axis('off')\n        slice_index = i+offset-1\n        plt.imshow(img[:,:,slice_index])\n        \n        if bboxes is not None and slice_index in bboxes['slice_number'].values:\n            bbox = bboxes[bboxes['slice_number'] == slice_index].to_dict(orient=\"records\")[0]\n\n            rect = patches.Rectangle((bbox['x'], bbox['y']), bbox['width'], bbox['height'], linewidth=1, edgecolor='r', facecolor='none')\n            ax.add_patch(rect)\n\n    if bboxes is not None:\n        \n        plt.figure(figsize=(20, 20))\n        for i in range(1, n+1):\n            ax = plt.subplot(7, 7, i)        \n            plt.axis('off')\n            slice_index = i+offset-1\n            img_slice = img[:,:,slice_index]\n\n            if slice_index in bboxes['slice_number'].values:\n                bbox = bboxes[bboxes['slice_number'] == slice_index].to_dict(orient=\"records\")[0]\n                \n                img_slice_in_bbox = img_slice[int(bbox['y']):int(bbox['y']+bbox['height']), int(bbox['x']):int(bbox['x']+bbox['width']), ]\n                \n                plt.imshow(img_slice_in_bbox)\n        \n        \n    # (optional) seg and image under seg\n    plt.figure(figsize=(20, 20))\n    if seg is not None:\n\n        for i in range(1, n+1):\n            ax = plt.subplot(7, 7, i)          \n            \n            plt.axis('off')\n            plt.imshow(seg[:,:,i+offset-1])\n            \n        plt.figure(figsize=(20, 20))\n        \n        for i in range(1, n+1):\n            ax = plt.subplot(7, 7, i)          \n            \n            plt.axis('off')\n            seg_mask = seg[:,:,i+offset-1] != 0\n            img_slice = img[:,:,i+offset-1].copy()\n            img_slice[~seg_mask ] = 0\n            \n            plt.imshow(img_slice)\n        \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:59:03.756058Z","iopub.execute_input":"2022-07-31T17:59:03.756522Z","iopub.status.idle":"2022-07-31T17:59:03.975337Z","shell.execute_reply.started":"2022-07-31T17:59:03.756486Z","shell.execute_reply":"2022-07-31T17:59:03.974254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from collections import Counter\n\ndef check_bbox_for_each_fracture(patient_id, cd):\n    train_record = train_df[train_df[\"StudyInstanceUID\"] == patient_id].to_dict(orient=\"records\")[0]\n\n    img, seg, bboxes = cd\n\n    seg_label_counter = Counter()\n    for slice_idx in bboxes['slice_number']:\n        bbox = bboxes[bboxes['slice_number'] == slice_idx].to_dict(orient=\"records\")[0]\n                \n        seg_slice_in_bbox = seg[int(bbox['y']):int(bbox['y']+bbox['height']), int(bbox['x']):int(bbox['x']+bbox['width']),slice_idx ]\n                        \n        seg_label_counter.update(seg_slice_in_bbox.flatten())\n\n\n    for i in range(1,8):\n        fracture_label = train_record[f\"C{i}\"] == 1\n        if fracture_label:\n            seg_exists = i in seg_label_counter.keys()\n            if not seg_exists:\n                print(f\"WARNING for {patient_id} train record {train_record} declares fracture in C{i}, but no bounding box includes seg of this class. inside bbox labels count: {seg_label_counter}\")\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:19:12.422811Z","iopub.execute_input":"2022-07-31T18:19:12.423664Z","iopub.status.idle":"2022-07-31T18:19:12.433541Z","shell.execute_reply.started":"2022-07-31T18:19:12.423624Z","shell.execute_reply":"2022-07-31T18:19:12.432641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id = bounding_boxes_with_seg['StudyInstanceUID'].values[0]\ncd = load_case_data(patient_id)\n\nfor offset in [0,100,200]:\n    display_patient(cd, n=7, offset=offset)\n\ndisplay_patient(cd, n=7, offset=cd[2]['slice_number'].min())\ndisplay_patient(cd, n=7, offset=cd[2]['slice_number'].min()+7)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:59:24.611885Z","iopub.execute_input":"2022-07-31T17:59:24.612302Z","iopub.status.idle":"2022-07-31T17:59:38.196605Z","shell.execute_reply.started":"2022-07-31T17:59:24.612258Z","shell.execute_reply":"2022-07-31T17:59:38.195212Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id = bounding_boxes_with_seg[[\"StudyInstanceUID\"]].drop_duplicates()[\"StudyInstanceUID\"].values[1]\ncd = load_case_data(patient_id)\n\nfor offset in [0,100,200]:\n    display_patient(cd, n=7, offset=offset)\n\ndisplay_patient(cd, n=7, offset=cd[2]['slice_number'].min())\ndisplay_patient(cd, n=7, offset=cd[2]['slice_number'].min()+7)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:00:25.826758Z","iopub.execute_input":"2022-07-31T18:00:25.827825Z","iopub.status.idle":"2022-07-31T18:00:40.193751Z","shell.execute_reply.started":"2022-07-31T18:00:25.827784Z","shell.execute_reply":"2022-07-31T18:00:40.192407Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_boxes_with_seg_and_train = bounding_boxes_with_seg.merge(train_df, on=\"StudyInstanceUID\")","metadata":{"execution":{"iopub.status.busy":"2022-07-31T17:55:40.162899Z","iopub.execute_input":"2022-07-31T17:55:40.163681Z","iopub.status.idle":"2022-07-31T17:55:40.177098Z","shell.execute_reply.started":"2022-07-31T17:55:40.163646Z","shell.execute_reply":"2022-07-31T17:55:40.176177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,8):\n    \n    examples = bounding_boxes_with_seg_and_train[bounding_boxes_with_seg_and_train[f\"C{i}\"] == 1]\n    patient_id = examples['StudyInstanceUID'].values[0]\n    cd = load_case_data(patient_id)\n    print(f\"C{i}\", train_df[train_df[\"StudyInstanceUID\"] == patient_id].to_dict(orient=\"records\")[0], patient_id, cd[2]['slice_number'].min(), cd[2]['slice_number'].max())\n    \n    display_patient(cd, n=7, offset=cd[2]['slice_number'].min())\n    display_patient(cd, n=7, offset=cd[2]['slice_number'].min()+7)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:02:19.622229Z","iopub.execute_input":"2022-07-31T18:02:19.623147Z","iopub.status.idle":"2022-07-31T18:03:37.793722Z","shell.execute_reply.started":"2022-07-31T18:02:19.623106Z","shell.execute_reply":"2022-07-31T18:03:37.79246Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,8):\n    \n    examples = bounding_boxes_with_seg_and_train[bounding_boxes_with_seg_and_train[f\"C{i}\"] == 1]\n    patient_id = examples['StudyInstanceUID'].values[0]\n    cd = load_case_data(patient_id)\n    print(f\"C{i}\", train_df[train_df[\"StudyInstanceUID\"] == patient_id].to_dict(orient=\"records\")[0], patient_id, cd[2]['slice_number'].min(), cd[2]['slice_number'].max())\n    \n    check_bbox_for_each_fracture(patient_id, cd)\n    \n    display_patient(cd, n=7, offset=cd[2]['slice_number'].min())\n    display_patient(cd, n=7, offset=cd[2]['slice_number'].min()+7)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:19:22.851697Z","iopub.execute_input":"2022-07-31T18:19:22.852146Z","iopub.status.idle":"2022-07-31T18:20:44.303115Z","shell.execute_reply.started":"2022-07-31T18:19:22.852107Z","shell.execute_reply":"2022-07-31T18:20:44.301895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:06:24.958425Z","iopub.execute_input":"2022-07-31T18:06:24.959072Z","iopub.status.idle":"2022-07-31T18:06:24.964342Z","shell.execute_reply.started":"2022-07-31T18:06:24.959033Z","shell.execute_reply":"2022-07-31T18:06:24.9635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-31T18:15:32.511733Z","iopub.execute_input":"2022-07-31T18:15:32.512141Z","iopub.status.idle":"2022-07-31T18:15:32.523284Z","shell.execute_reply.started":"2022-07-31T18:15:32.512109Z","shell.execute_reply":"2022-07-31T18:15:32.521933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}