{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames[:3]:\n        pass\n        #print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-05T17:05:36.172521Z","iopub.execute_input":"2022-09-05T17:05:36.172956Z","iopub.status.idle":"2022-09-05T17:07:21.166505Z","shell.execute_reply.started":"2022-09-05T17:05:36.172919Z","shell.execute_reply":"2022-09-05T17:07:21.165526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# From https://www.kaggle.com/code/samuelcortinhas/rsna-fracture-detection-in-depth-eda\n'''Offline (need to add dataset --> for-pydicom)'''\n!pip install gdcm","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:19:26.793946Z","iopub.execute_input":"2022-09-05T17:19:26.794491Z","iopub.status.idle":"2022-09-05T17:19:40.657739Z","shell.execute_reply.started":"2022-09-05T17:19:26.794437Z","shell.execute_reply":"2022-09-05T17:19:40.656316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:19:48.558242Z","iopub.execute_input":"2022-09-05T17:19:48.558653Z","iopub.status.idle":"2022-09-05T17:19:48.668093Z","shell.execute_reply.started":"2022-09-05T17:19:48.55862Z","shell.execute_reply":"2022-09-05T17:19:48.666357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport glob\nimport pydicom\nimport nibabel as nib\nimport pandas as pd\nimport numpy as np\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:21.168096Z","iopub.execute_input":"2022-09-05T17:07:21.168439Z","iopub.status.idle":"2022-09-05T17:07:21.968618Z","shell.execute_reply.started":"2022-09-05T17:07:21.168409Z","shell.execute_reply":"2022-09-05T17:07:21.967611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = \"../input/rsna-2022-cervical-spine-fracture-detection\"\nTRAIN_DIR = os.path.join(DATA_DIR, \"train_images\")\nSEGM_DIR = os.path.join(DATA_DIR, \"segmentations\")\n\ntrain_df = pd.read_csv(os.path.join(DATA_DIR, \"train.csv\"))\nprint(train_df.shape)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:21.969721Z","iopub.execute_input":"2022-09-05T17:07:21.97002Z","iopub.status.idle":"2022-09-05T17:07:22.004953Z","shell.execute_reply.started":"2022-09-05T17:07:21.969993Z","shell.execute_reply":"2022-09-05T17:07:22.003837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_theme()\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 12))\nsns.countplot(x=\"patient_overall\", data=train_df, ax=ax1)\nax1.set_title(\"Fracture overall\")\n\ntrain_df_melt = pd.melt(train_df, id_vars=[\"StudyInstanceUID\", \"patient_overall\"], var_name=\"cervical_vertebrae\", value_name=\"fracture\")\nsns.countplot(x=\"cervical_vertebrae\", hue=\"fracture\", data=train_df_melt, ax=ax2)\nax2.set_title(\"Fracture of cervical vertebrae\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:15.261799Z","iopub.execute_input":"2022-09-05T16:51:15.264218Z","iopub.status.idle":"2022-09-05T16:51:15.764648Z","shell.execute_reply.started":"2022-09-05T16:51:15.264156Z","shell.execute_reply":"2022-09-05T16:51:15.763051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nsns.countplot(x=train_df.iloc[:, 2:].sum(axis=1))\nplt.xlabel(\"number of fractures\")\nplt.title(\"Number of fractures per patient\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:15.766663Z","iopub.execute_input":"2022-09-05T16:51:15.767056Z","iopub.status.idle":"2022-09-05T16:51:16.057728Z","shell.execute_reply.started":"2022-09-05T16:51:15.767024Z","shell.execute_reply":"2022-09-05T16:51:16.056307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_fracture_indices(train_df, num_frac):\n    df = train_df[train_df.iloc[:, 2:].sum(axis=1) == num_frac].iloc[:, 2:]\n    # create a np array with the column indices\n    col_idx_tmp = np.tile(np.arange(df.shape[1]), df.shape[0])\n    col_idx = np.reshape(col_idx_tmp, df.shape)\n    # select column indices in each row that are nonzero, i.e. fractures\n    nonzero_col_idx = col_idx[df.to_numpy(dtype=bool)]\n    return nonzero_col_idx","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:16.059131Z","iopub.execute_input":"2022-09-05T16:51:16.059466Z","iopub.status.idle":"2022-09-05T16:51:16.068042Z","shell.execute_reply.started":"2022-09-05T16:51:16.059436Z","shell.execute_reply":"2022-09-05T16:51:16.066586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" #patients with two fractures\ntwo_frac_indices = get_fracture_indices(train_df, 2)\ndist_btw_fractures = np.diff(two_frac_indices.reshape(-1, 2), axis=1).flatten()\n\nplt.figure(figsize=(16, 10))\nsns.countplot(x=dist_btw_fractures)\nplt.xlabel(\"distance between fractured cervical vertebrae\")\nplt.title(\"Distance between fractured cervical vertebrae for patients with two fractures (e.g. C1 and C3 have distance 2)\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:16.071424Z","iopub.execute_input":"2022-09-05T16:51:16.073098Z","iopub.status.idle":"2022-09-05T16:51:16.367129Z","shell.execute_reply.started":"2022-09-05T16:51:16.073048Z","shell.execute_reply":"2022-09-05T16:51:16.365999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# patients with three fractures\nthree_frac_indices = get_fracture_indices(train_df, 3)\ndist_btw_subseq_frac = np.diff(three_frac_indices.reshape(-1, 3), axis=1).flatten()\npct_patients_w_subseq_frac = (dist_btw_subseq_frac.reshape(-1, 2).sum(axis=1) == 2).mean()\n\nplt.figure(figsize=(12, 8))\nplt.bar(x=[\"\\w subsequent fractures\", \"\\wo subsequent fractures\"], height=[pct_patients_w_subseq_frac, 1-pct_patients_w_subseq_frac], width=0.5)\nplt.ylabel(\"proportion of patients\")\nplt.title(\"Patients with 3 fractures\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:16.368812Z","iopub.execute_input":"2022-09-05T16:51:16.369706Z","iopub.status.idle":"2022-09-05T16:51:16.598486Z","shell.execute_reply.started":"2022-09-05T16:51:16.369655Z","shell.execute_reply":"2022-09-05T16:51:16.597071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"example = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.849/1.dcm\"\nexample_ds = pydicom.dcmread(example)\nexample_ds","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:16.60051Z","iopub.execute_input":"2022-09-05T16:51:16.601022Z","iopub.status.idle":"2022-09-05T16:51:16.62378Z","shell.execute_reply.started":"2022-09-05T16:51:16.600984Z","shell.execute_reply":"2022-09-05T16:51:16.622796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# source: https://www.kaggle.com/code/allunia/rsna-csf-cervical-spine-fracture-eda/notebook\ndef rescale_img_to_hu(dcm_ds):\n    \"\"\"Rescales the image to Hounsfield unit.\n    \"\"\"\n    return dcm_ds.pixel_array * dcm_ds.RescaleSlope + dcm_ds.RescaleIntercept","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:12:16.28256Z","iopub.execute_input":"2022-09-05T17:12:16.28296Z","iopub.status.idle":"2022-09-05T17:12:16.289759Z","shell.execute_reply.started":"2022-09-05T17:12:16.282929Z","shell.execute_reply":"2022-09-05T17:12:16.288511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# original image\nfig, axs = plt.subplots(2, 2, figsize=(24, 12))\naxs[0, 0].imshow(example_ds.pixel_array, cmap=\"bone\")\naxs[0, 0].axis(\"off\")\nsns.histplot(example_ds.pixel_array.flatten(), ax=axs[0, 1])\n\n# rescaled image\nrescaled_img = rescale_img_to_hu(example_ds)\naxs[1, 0].imshow(rescaled_img, cmap=\"bone\")\naxs[1, 0].axis(\"off\")\nsns.histplot(rescaled_img.flatten(), ax=axs[1, 1])","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:16.634144Z","iopub.execute_input":"2022-09-05T16:51:16.634536Z","iopub.status.idle":"2022-09-05T16:51:18.374588Z","shell.execute_reply.started":"2022-09-05T16:51:16.634502Z","shell.execute_reply":"2022-09-05T16:51:18.373143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_slices_for_patient(patient_id, nrows, ncols):\n    patient_dir = os.path.join(TRAIN_DIR, patient_id)\n    num_slices = len(glob.glob(f\"{patient_dir}/*\"))\n    print(f\"Number of slices for patient: {num_slices}\")\n    fig, axs = plt.subplots(nrows, ncols, figsize=(24,15))\n    axs = axs.flatten()\n    for i in range(min(num_slices, nrows*ncols)):\n        # dicom filenames start from 1\n        ds = pydicom.dcmread(os.path.join(patient_dir, f\"{i+1}.dcm\"))\n        axs[i].imshow(rescale_img_to_hu(ds), cmap=\"bone\")\n        axs[i].axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:18.37615Z","iopub.execute_input":"2022-09-05T16:51:18.376523Z","iopub.status.idle":"2022-09-05T16:51:18.386377Z","shell.execute_reply.started":"2022-09-05T16:51:18.376492Z","shell.execute_reply":"2022-09-05T16:51:18.384624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_slices_for_patient(\"1.2.826.0.1.3680043.849\", 4, 6)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:18.390829Z","iopub.execute_input":"2022-09-05T16:51:18.391259Z","iopub.status.idle":"2022-09-05T16:51:21.442252Z","shell.execute_reply.started":"2022-09-05T16:51:18.391227Z","shell.execute_reply":"2022-09-05T16:51:21.436876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def calc_num_slices_per_patient(train_df):\n    num_slices = []\n    for patient_id in train_df[\"StudyInstanceUID\"]:\n        slice_paths = glob.glob(f\"{TRAIN_DIR}/{patient_id}/*\")\n        num_slices.append(len(slice_paths))\n    train_df[\"num_slices\"] = num_slices\n    return train_df","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:21.443811Z","iopub.execute_input":"2022-09-05T16:51:21.444982Z","iopub.status.idle":"2022-09-05T16:51:21.453588Z","shell.execute_reply.started":"2022-09-05T16:51:21.444929Z","shell.execute_reply":"2022-09-05T16:51:21.452005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = calc_num_slices_per_patient(train_df)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:21.456731Z","iopub.execute_input":"2022-09-05T16:51:21.458102Z","iopub.status.idle":"2022-09-05T16:51:25.065411Z","shell.execute_reply.started":"2022-09-05T16:51:21.458022Z","shell.execute_reply":"2022-09-05T16:51:25.064075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16, 10))\nsns.histplot(x=\"num_slices\", data=train_df)\nplt.title(\"Histogram of number of slices per patient\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:25.067552Z","iopub.execute_input":"2022-09-05T16:51:25.068297Z","iopub.status.idle":"2022-09-05T16:51:25.429404Z","shell.execute_reply.started":"2022-09-05T16:51:25.06824Z","shell.execute_reply":"2022-09-05T16:51:25.427884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# nibabel docs: https://nipy.org/nibabel/nifti_images.html?highlight=nifti\nexample_path = \"../input/rsna-2022-cervical-spine-fracture-detection/segmentations/1.2.826.0.1.3680043.849.nii\"\nexample_segm_mask = nib.load(example_path)\nprint(example_segm_mask.header)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:25.4313Z","iopub.execute_input":"2022-09-05T16:51:25.431683Z","iopub.status.idle":"2022-09-05T16:51:25.461106Z","shell.execute_reply.started":"2022-09-05T16:51:25.431647Z","shell.execute_reply":"2022-09-05T16:51:25.459545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"type(example_segm_mask)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:25.46248Z","iopub.status.idle":"2022-09-05T16:51:25.463422Z","shell.execute_reply.started":"2022-09-05T16:51:25.463117Z","shell.execute_reply":"2022-09-05T16:51:25.463152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_segm_mask.affine.shape\n","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:13.200016Z","iopub.execute_input":"2022-08-29T17:58:13.200336Z","iopub.status.idle":"2022-08-29T17:58:13.206962Z","shell.execute_reply.started":"2022-08-29T17:58:13.200304Z","shell.execute_reply":"2022-08-29T17:58:13.205768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q=example_segm_mask.get_fdata()","metadata":{"execution":{"iopub.status.busy":"2022-08-29T18:07:21.468396Z","iopub.execute_input":"2022-08-29T18:07:21.468797Z","iopub.status.idle":"2022-08-29T18:07:21.473374Z","shell.execute_reply.started":"2022-08-29T18:07:21.46877Z","shell.execute_reply":"2022-08-29T18:07:21.472561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h=example_segm_mask.header","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:13.865479Z","iopub.execute_input":"2022-08-29T17:58:13.866268Z","iopub.status.idle":"2022-08-29T17:58:13.870228Z","shell.execute_reply.started":"2022-08-29T17:58:13.866242Z","shell.execute_reply":"2022-08-29T17:58:13.868987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(q[:,:,1])","metadata":{"execution":{"iopub.status.busy":"2022-08-29T18:07:51.663217Z","iopub.execute_input":"2022-08-29T18:07:51.663599Z","iopub.status.idle":"2022-08-29T18:07:51.883319Z","shell.execute_reply.started":"2022-08-29T18:07:51.663575Z","shell.execute_reply":"2022-08-29T18:07:51.881504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segm_labels = np.unique(q[:, :, 100][q[:, :, 100].nonzero()])","metadata":{"execution":{"iopub.status.busy":"2022-08-29T18:14:35.906099Z","iopub.execute_input":"2022-08-29T18:14:35.906489Z","iopub.status.idle":"2022-08-29T18:14:35.913522Z","shell.execute_reply.started":"2022-08-29T18:14:35.906464Z","shell.execute_reply":"2022-08-29T18:14:35.912683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nimport numpy\nnumpy.set_printoptions(threshold=10)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:51:25.464554Z","iopub.status.idle":"2022-09-05T16:51:25.465453Z","shell.execute_reply.started":"2022-09-05T16:51:25.465231Z","shell.execute_reply":"2022-09-05T16:51:25.465253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"segm_labels","metadata":{"execution":{"iopub.status.busy":"2022-08-29T18:16:16.443465Z","iopub.execute_input":"2022-08-29T18:16:16.443827Z","iopub.status.idle":"2022-08-29T18:16:16.45114Z","shell.execute_reply.started":"2022-08-29T18:16:16.443803Z","shell.execute_reply":"2022-08-29T18:16:16.450335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q[:, :, :].max()","metadata":{"execution":{"iopub.status.busy":"2022-08-29T18:19:04.297785Z","iopub.execute_input":"2022-08-29T18:19:04.298124Z","iopub.status.idle":"2022-08-29T18:19:04.334782Z","shell.execute_reply.started":"2022-08-29T18:19:04.298099Z","shell.execute_reply":"2022-08-29T18:19:04.333906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[train_df[\"StudyInstanceUID\"] == \"1.2.826.0.1.3680043.10921\"]","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:48.004086Z","iopub.execute_input":"2022-08-29T17:58:48.004432Z","iopub.status.idle":"2022-08-29T17:58:48.019447Z","shell.execute_reply.started":"2022-08-29T17:58:48.004406Z","shell.execute_reply":"2022-08-29T17:58:48.018083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_segm_for_patient(patient_id, nrows, ncols, step=1):\n    \"\"\"Shows slices with segmentation masks for the patient, skips slices that have empty segmentation masks.\"\"\"\n    num_slices = train_df.loc[train_df[\"StudyInstanceUID\"] == patient_id, \"num_slices\"].values[0]\n    print(f\"Number of slices for patient: {num_slices}\")\n    \n    print(f\"Fracture information for patient: \")\n    print(f\"{train_df[train_df['StudyInstanceUID'] == patient_id].iloc[:, 1:-1]}\")\n    patient_dir = os.path.join(TRAIN_DIR, patient_id)\n    \n    segm_path = os.path.join(SEGM_DIR, f\"{patient_id}.nii\")\n    # source: https://www.kaggle.com/code/kretes/segmentations-fracture-zoom-in\n    segm_mask = nib.load(segm_path).get_fdata()\n        \n    # flip in z axis\n    segm_mask = np.flip(segm_mask, axis=-1)\n    # rotate 90 degrees in xy\n    segm_mask = np.rot90(segm_mask, axes=(0, 1))\n        \n    fig, axs = plt.subplots(nrows, ncols, figsize=(24,15))\n    axs = axs.flatten()\n    \n    count = 0\n    idx = 0\n    while count < nrows*ncols:\n        if segm_mask[:, :, idx].max() > 0:\n            # dicom filenames start from 1\n            #ds = pydicom.dcmread(os.path.join(patient_dir, f\"{idx+1}.dcm\"))\n            #axs[count].imshow(rescale_img_to_hu(ds), cmap=\"bone\")\n            #axs[count].axis(\"off\")\n            segm_im = axs[count].imshow(segm_mask[:, :, idx], alpha=0.4)\n            segm_max = segm_mask[:, :, idx].max()\n            \n            segm_labels = np.unique(segm_mask[:, :, idx][segm_mask[:, :, idx].nonzero()])\n            segm_colors = [segm_im.cmap(label/segm_max) for label in segm_labels]\n            ptch = [patches.Patch(color=segm_colors[i], label=f\"C{int(segm_labels[i])}\") for i in range(len(segm_labels))]\n            axs[count].legend(handles=ptch)\n            count += 1\n        idx += step","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:49.287616Z","iopub.execute_input":"2022-08-29T17:58:49.288135Z","iopub.status.idle":"2022-08-29T17:58:49.29851Z","shell.execute_reply.started":"2022-08-29T17:58:49.288111Z","shell.execute_reply":"2022-08-29T17:58:49.297606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_segm_for_patient(\"1.2.826.0.1.3680043.10921\", nrows=4, ncols=6, step=8)","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:49.849482Z","iopub.execute_input":"2022-08-29T17:58:49.850842Z","iopub.status.idle":"2022-08-29T17:58:55.120851Z","shell.execute_reply.started":"2022-08-29T17:58:49.850799Z","shell.execute_reply":"2022-08-29T17:58:55.119766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bboxes_df = pd.read_csv(os.path.join(DATA_DIR, \"train_bounding_boxes.csv\"))\nprint(bboxes_df.shape)\nbboxes_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:22.007342Z","iopub.execute_input":"2022-09-05T17:07:22.007642Z","iopub.status.idle":"2022-09-05T17:07:22.040852Z","shell.execute_reply.started":"2022-09-05T17:07:22.007614Z","shell.execute_reply":"2022-09-05T17:07:22.039793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Number of patients with bounding boxes: {bboxes_df['StudyInstanceUID'].nunique()}\")","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:22.042466Z","iopub.execute_input":"2022-09-05T17:07:22.043011Z","iopub.status.idle":"2022-09-05T17:07:22.055469Z","shell.execute_reply.started":"2022-09-05T17:07:22.042969Z","shell.execute_reply":"2022-09-05T17:07:22.054266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_bbox = train_df[train_df[\"StudyInstanceUID\"].isin(bboxes_df[\"StudyInstanceUID\"])].drop(columns=\"num_slices\")\n\nsns.set_theme()\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 12))\nsns.countplot(x=\"patient_overall\", data=train_df_bbox, ax=ax1)\nax1.set_title(\"Fracture overall (patients with bounding boxes)\")\n\ntrain_df_bbox_melt = pd.melt(train_df_bbox, id_vars=[\"StudyInstanceUID\", \"patient_overall\"], var_name=\"cervical_vertebrae\", value_name=\"fracture\")\nsns.countplot(x=\"cervical_vertebrae\", hue=\"fracture\", data=train_df_bbox_melt, ax=ax2)\nax2.set_title(\"Fracture of cervical vertebrae (patients with bounding boxes)\");","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:22.057004Z","iopub.execute_input":"2022-09-05T17:07:22.057593Z","iopub.status.idle":"2022-09-05T17:07:22.141058Z","shell.execute_reply.started":"2022-09-05T17:07:22.05756Z","shell.execute_reply":"2022-09-05T17:07:22.139029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q=train_df[train_df['StudyInstanceUID'] == j].iloc[:,:-1].to_numpy()[0]","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:22.142042Z","iopub.status.idle":"2022-09-05T17:07:22.142427Z","shell.execute_reply.started":"2022-09-05T17:07:22.142236Z","shell.execute_reply":"2022-09-05T17:07:22.142254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(X)","metadata":{"execution":{"iopub.status.busy":"2022-09-01T16:27:16.057944Z","iopub.execute_input":"2022-09-01T16:27:16.058452Z","iopub.status.idle":"2022-09-01T16:27:16.06672Z","shell.execute_reply.started":"2022-09-01T16:27:16.058414Z","shell.execute_reply":"2022-09-01T16:27:16.06582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nbase_path = \"../input/rsna-2022-cervical-spine-fracture-detection\"\n\ndef plot_fracture(slice_num,bbox_id,ax_id1,ax_id2):\n    file = pydicom.dcmread(f\"{base_path}/train_images/{bbox_id}/{slice_num}.dcm\")\n    img = apply_voi_lut(file.pixel_array, file)\n    info = bounding_box[(bounding_box['StudyInstanceUID']==bbox_id)&(bounding_box['slice_number']==slice_num)]\n    #rect = patches.Rectangle((float(info.x), float(info.y)), float(info.width), float(info.height), linewidth=3, edgecolor='r', facecolor='none')\n\n    axes[ax_id1,ax_id2].imshow(img, cmap=\"bone\")\n    #axes[ax_id1,ax_id2].add_patch(rect)\n    axes[ax_id1,ax_id2].set_title(f\"ID:{bbox_id}, Slice: {slice_num}\", fontsize=20, weight='bold',y=1.02)\n    axes[ax_id1,ax_id2].axis('off')\n\nfig, axes = plt.subplots(nrows=2, ncols=2, figsize=(18,18))\nplot_fracture(146,'1.2.826.0.1.3680043.10051',0,0)\nplot_fracture(151,'1.2.826.0.1.3680043.10678',0,1)\n#plot_fracture(174,'1.2.826.0.1.3680043.10678',1,0)\n#plot_fracture(90,'1.2.826.0.1.3680043.10732',1,1)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:21:18.388098Z","iopub.execute_input":"2022-09-05T17:21:18.388507Z","iopub.status.idle":"2022-09-05T17:21:19.010484Z","shell.execute_reply.started":"2022-09-05T17:21:18.388475Z","shell.execute_reply":"2022-09-05T17:21:19.009024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"j='1.2.826.0.1.3680043.10678'\npatient_dir='/kaggle/input/rsna-2022-cervical-spine-fracture-detection/train_images/' + j\nds = pydicom.dcmread(os.path.join(patient_dir, f\"{118}.dcm\"))","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:59:11.373128Z","iopub.execute_input":"2022-09-05T16:59:11.373536Z","iopub.status.idle":"2022-09-05T16:59:11.383363Z","shell.execute_reply.started":"2022-09-05T16:59:11.373503Z","shell.execute_reply":"2022-09-05T16:59:11.382047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds = pydicom.dcmread(\"/kaggle/input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10678/170.dcm\")","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:33:00.812321Z","iopub.execute_input":"2022-09-05T17:33:00.812764Z","iopub.status.idle":"2022-09-05T17:33:00.822194Z","shell.execute_reply.started":"2022-09-05T17:33:00.812733Z","shell.execute_reply":"2022-09-05T17:33:00.821221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image=[]\nX=[]\nY=[]\nW=[]\nH=[]\npate=[]\n\nfor j in list(bb['StudyInstanceUID'][:5]):\n    \n    #patient_dir = os.path.join(TRAIN_DIR, j)\n    #num_slices = len(glob.glob(f\"{patient_dir}/*\"))\n    #print(f\"Number of slices for patient: {num_slices}\")\n    patient_dir='/kaggle/input/rsna-2022-cervical-spine-fracture-detection/train_images/' + j \n    bboxes_patient_df = bounding_box[bounding_box[\"StudyInstanceUID\"] == j]\n    num_bboxes = bboxes_patient_df.shape[0]\n    #print(f\"Number of bounding boxes for patient: {num_bboxes}\")\n    pate.append( train_df[train_df['StudyInstanceUID'] == j].iloc[:,:-1].to_numpy()[0] )\n    \n\n\n    for i in range(num_bboxes):\n        while True:\n            try:\n\n                slice_number = bboxes_patient_df.iloc[i][\"slice_number\"]\n                #print(slice_number)\n                #slice_number=math.floor(float(slice_number))\n                ds = pydicom.dcmread(os.path.join(patient_dir, f\"{slice_number}.dcm\"), force=True)\n                image.append(rescale_img_to_hu(ds))\n\n                X.append(bboxes_patient_df.iloc[i][\"x\"])\n                Y.append(bboxes_patient_df.iloc[i][\"y\"])\n                W.append(bboxes_patient_df.iloc[i][\"width\"])    \n                H.append(bboxes_patient_df.iloc[i][\"height\"])\n            except:\n                continue\n                #print(os.path.join(patient_dir, f\"{slice_number}.dcm\"),\"Not present\")\n            break\n","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:35:05.587581Z","iopub.execute_input":"2022-09-05T17:35:05.58826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pydicom import dcmread\nimport pylibjpeg\n#import gdcm","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:20:29.792509Z","iopub.execute_input":"2022-09-05T17:20:29.792927Z","iopub.status.idle":"2022-09-05T17:20:29.8882Z","shell.execute_reply.started":"2022-09-05T17:20:29.792887Z","shell.execute_reply":"2022-09-05T17:20:29.886558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U python-gdcm -\n","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:20:10.117548Z","iopub.execute_input":"2022-09-05T17:20:10.117973Z","iopub.status.idle":"2022-09-05T17:20:21.572857Z","shell.execute_reply.started":"2022-09-05T17:20:10.117937Z","shell.execute_reply":"2022-09-05T17:20:21.571609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pydicom import dcmread\nfrom pydicom.pixel_data_handlers import pillow_handler\npillow_handler.PillowJPEGTransferSyntaxes.append('/kaggle/input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10678/73.dcm')\n\nds = dcmread('/kaggle/input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10678/73.dcm')\narr = ds.pixel_array","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:28:13.082692Z","iopub.execute_input":"2022-09-05T17:28:13.083516Z","iopub.status.idle":"2022-09-05T17:28:13.114357Z","shell.execute_reply.started":"2022-09-05T17:28:13.083458Z","shell.execute_reply":"2022-09-05T17:28:13.11252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd \nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nimport seaborn as sns\nimport pydicom\nimport nibabel as nib\nimport os\nimport PIL\n\nfrom pprint import pprint\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nfrom tqdm import tqdm\nfrom glob import glob","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:28:08.188035Z","iopub.execute_input":"2022-09-05T17:28:08.188475Z","iopub.status.idle":"2022-09-05T17:28:08.195214Z","shell.execute_reply.started":"2022-09-05T17:28:08.188444Z","shell.execute_reply":"2022-09-05T17:28:08.194053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(X)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"show_bboxes_for_patient(\"1.2.826.0.1.3680043.10051\", 10, 3)","metadata":{"execution":{"iopub.status.busy":"2022-08-29T17:58:55.556111Z","iopub.execute_input":"2022-08-29T17:58:55.556737Z","iopub.status.idle":"2022-08-29T17:58:58.674663Z","shell.execute_reply.started":"2022-08-29T17:58:55.55671Z","shell.execute_reply":"2022-08-29T17:58:58.673115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head","metadata":{"execution":{"iopub.status.busy":"2022-08-30T15:26:16.532619Z","iopub.execute_input":"2022-08-30T15:26:16.533032Z","iopub.status.idle":"2022-08-30T15:26:16.552283Z","shell.execute_reply.started":"2022-08-30T15:26:16.532997Z","shell.execute_reply":"2022-08-30T15:26:16.551205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_box=pd.read_csv(os.path.join(DATA_DIR, \"train_bounding_boxes.csv\"))","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:11.777708Z","iopub.execute_input":"2022-09-05T17:08:11.778153Z","iopub.status.idle":"2022-09-05T17:08:11.797048Z","shell.execute_reply.started":"2022-09-05T17:08:11.778119Z","shell.execute_reply":"2022-09-05T17:08:11.79587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_box.groupby(['StudyInstanceUID'])['slice_number'].count()","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:12.367077Z","iopub.execute_input":"2022-09-05T17:08:12.367965Z","iopub.status.idle":"2022-09-05T17:08:12.380817Z","shell.execute_reply.started":"2022-09-05T17:08:12.367926Z","shell.execute_reply":"2022-09-05T17:08:12.379949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_box[\"x\"]=bounding_box[\"x\"].astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:12.592484Z","iopub.execute_input":"2022-09-05T17:08:12.592915Z","iopub.status.idle":"2022-09-05T17:08:12.604281Z","shell.execute_reply.started":"2022-09-05T17:08:12.592879Z","shell.execute_reply":"2022-09-05T17:08:12.603003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bounding_box[\"y\"]=bounding_box[\"y\"].astype(str)\nbounding_box[\"width\"]=bounding_box[\"width\"].astype(str)\nbounding_box[\"height\"]=bounding_box[\"height\"].astype(str)\nbounding_box[\"slice_number\"]=bounding_box[\"slice_number\"].astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:12.73344Z","iopub.execute_input":"2022-09-05T17:08:12.734255Z","iopub.status.idle":"2022-09-05T17:08:12.764831Z","shell.execute_reply.started":"2022-09-05T17:08:12.734214Z","shell.execute_reply":"2022-09-05T17:08:12.763621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb=bounding_box.groupby(['StudyInstanceUID'], as_index=False, sort=False).agg({'x': lambda q: ','.join(q),'y':  lambda q: ','.join(q),'width':  lambda q: ','.join(q),'height':  lambda q: ','.join(q),'slice_number':  lambda q: ','.join(q),})","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:13.531905Z","iopub.execute_input":"2022-09-05T17:08:13.532561Z","iopub.status.idle":"2022-09-05T17:08:13.564304Z","shell.execute_reply.started":"2022-09-05T17:08:13.532525Z","shell.execute_reply":"2022-09-05T17:08:13.56339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:08:14.176862Z","iopub.execute_input":"2022-09-05T17:08:14.177539Z","iopub.status.idle":"2022-09-05T17:08:14.193252Z","shell.execute_reply.started":"2022-09-05T17:08:14.177494Z","shell.execute_reply":"2022-09-05T17:08:14.19212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb['slice_number'][0]","metadata":{"execution":{"iopub.status.busy":"2022-09-05T17:07:22.155958Z","iopub.status.idle":"2022-09-05T17:07:22.15638Z","shell.execute_reply.started":"2022-09-05T17:07:22.156172Z","shell.execute_reply":"2022-09-05T17:07:22.156192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb['slice_number'][5].split(',').astype(float)","metadata":{"execution":{"iopub.status.busy":"2022-09-05T16:50:21.511589Z","iopub.execute_input":"2022-09-05T16:50:21.51205Z","iopub.status.idle":"2022-09-05T16:50:21.540711Z","shell.execute_reply.started":"2022-09-05T16:50:21.512008Z","shell.execute_reply":"2022-09-05T16:50:21.538875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q=[float(i) for i in bb['slice_number'][0].split(',')]","metadata":{"execution":{"iopub.status.busy":"2022-08-30T15:48:51.519074Z","iopub.execute_input":"2022-08-30T15:48:51.51949Z","iopub.status.idle":"2022-08-30T15:48:51.52639Z","shell.execute_reply.started":"2022-08-30T15:48:51.519457Z","shell.execute_reply":"2022-08-30T15:48:51.524876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-30T15:51:07.053335Z","iopub.execute_input":"2022-08-30T15:51:07.053737Z","iopub.status.idle":"2022-08-30T15:51:07.061651Z","shell.execute_reply.started":"2022-08-30T15:51:07.053704Z","shell.execute_reply":"2022-08-30T15:51:07.060496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bb['StudyInstanceUID'][0]","metadata":{"execution":{"iopub.status.busy":"2022-08-30T15:49:38.849484Z","iopub.execute_input":"2022-08-30T15:49:38.849886Z","iopub.status.idle":"2022-08-30T15:49:38.857513Z","shell.execute_reply.started":"2022-08-30T15:49:38.849853Z","shell.execute_reply":"2022-08-30T15:49:38.856555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cd = pd.merge(train_df, bb, how='left',on='StudyInstanceUID').drop_duplicates(subset=['StudyInstanceUID'],keep=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:45:37.135335Z","iopub.execute_input":"2022-08-29T19:45:37.135691Z","iopub.status.idle":"2022-08-29T19:45:37.150241Z","shell.execute_reply.started":"2022-08-29T19:45:37.135666Z","shell.execute_reply":"2022-08-29T19:45:37.149226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=df_cd.loc[(df_cd['x'].notnull()) ]","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:47:55.623119Z","iopub.execute_input":"2022-08-29T19:47:55.62434Z","iopub.status.idle":"2022-08-29T19:47:55.630914Z","shell.execute_reply.started":"2022-08-29T19:47:55.624287Z","shell.execute_reply":"2022-08-29T19:47:55.630099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:48:00.50272Z","iopub.execute_input":"2022-08-29T19:48:00.503094Z","iopub.status.idle":"2022-08-29T19:48:00.507627Z","shell.execute_reply.started":"2022-08-29T19:48:00.503069Z","shell.execute_reply":"2022-08-29T19:48:00.506701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:48:01.953457Z","iopub.execute_input":"2022-08-29T19:48:01.953972Z","iopub.status.idle":"2022-08-29T19:48:01.968705Z","shell.execute_reply.started":"2022-08-29T19:48:01.953948Z","shell.execute_reply":"2022-08-29T19:48:01.967588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:48:12.644584Z","iopub.execute_input":"2022-08-29T19:48:12.644914Z","iopub.status.idle":"2022-08-29T19:48:12.664393Z","shell.execute_reply.started":"2022-08-29T19:48:12.644888Z","shell.execute_reply":"2022-08-29T19:48:12.663739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.index[train[\"StudyInstanceUID\"] == '1.2.826.0.1.3680043.5482'][0]","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:58:35.238197Z","iopub.execute_input":"2022-08-29T19:58:35.238681Z","iopub.status.idle":"2022-08-29T19:58:35.247242Z","shell.execute_reply.started":"2022-08-29T19:58:35.238646Z","shell.execute_reply":"2022-08-29T19:58:35.246138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patient_id = '1.2.826.0.1.3680043.10051'\npatient_dir = os.path.join(TRAIN_DIR, patient_id)\nnum_slices = len(glob.glob(f\"{patient_dir}/*\"))\nprint(f\"Number of slices for patient: {num_slices}\")\nr=train.index[train[\"StudyInstanceUID\"] == patient_id][0]\nbboxes_patient_df = train[train[\"StudyInstanceUID\"] == patient_id]\nnum_bboxes = bboxes_patient_df['slice_number'][r].split(',')\nprint(f\"Number of bounding boxes for patient: {num_bboxes}\")\n\nprint(f\"Fracture information for patient: \")\nprint(f\"{train_df[train_df['StudyInstanceUID'] == patient_id].iloc[:, 1:-1]}\")\n\nfor i in range(len(num_bboxes)):\n        #i=0\n    try:\n        slice_number = float(bboxes_patient_df['slice_number'][r].split(',')[i])\n        ds = pydicom.dcmread(os.path.join(patient_dir, f\"{slice_number}.dcm\"))\n        axs[i].imshow(rescale_img_to_hu(ds), cmap=\"bone\")\n        axs[i].axis(\"off\")\n\n        x = float(bboxes_patient_df['x'][r].split(',')[i])\n        y = float(bboxes_patient_df['y'][r].split(',')[i])\n        width = float(bboxes_patient_df['width'][r].split(',')[i])\n        height = float(bboxes_patient_df['height'][r].split(',')[i])\n        rect = patches.Rectangle((x, y), width, height, fill=False, edgecolor=\"blue\", linewidth=1.5)\n        axs[i].add_patch(rect)\n    except:\n        print(os.path.join(patient_dir, f\"{slice_number}.dcm\"))","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:59:39.20395Z","iopub.execute_input":"2022-08-29T19:59:39.204291Z","iopub.status.idle":"2022-08-29T19:59:39.241373Z","shell.execute_reply.started":"2022-08-29T19:59:39.204264Z","shell.execute_reply":"2022-08-29T19:59:39.240678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bboxes_patient_df = train[train[\"StudyInstanceUID\"] == patient_id]\nnum_bboxes = len(bboxes_patient_df['slice_number'][0].split(','))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bboxes_patient_df = train[train[\"StudyInstanceUID\"] == patient_id]","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:38:17.066768Z","iopub.execute_input":"2022-08-29T19:38:17.06708Z","iopub.status.idle":"2022-08-29T19:38:17.07225Z","shell.execute_reply.started":"2022-08-29T19:38:17.067057Z","shell.execute_reply":"2022-08-29T19:38:17.071481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(bboxes_patient_df['slice_number'].str.split(','))","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:39:32.791715Z","iopub.execute_input":"2022-08-29T19:39:32.792401Z","iopub.status.idle":"2022-08-29T19:39:32.801155Z","shell.execute_reply.started":"2022-08-29T19:39:32.79235Z","shell.execute_reply":"2022-08-29T19:39:32.79994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q=bboxes_patient_df['slice_number'].str.split(',')","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:41:52.153Z","iopub.execute_input":"2022-08-29T19:41:52.153318Z","iopub.status.idle":"2022-08-29T19:41:52.159688Z","shell.execute_reply.started":"2022-08-29T19:41:52.153296Z","shell.execute_reply":"2022-08-29T19:41:52.158354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-08-29T19:42:03.619096Z","iopub.execute_input":"2022-08-29T19:42:03.619419Z","iopub.status.idle":"2022-08-29T19:42:03.627129Z","shell.execute_reply.started":"2022-08-29T19:42:03.619394Z","shell.execute_reply":"2022-08-29T19:42:03.625995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}