{"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 os\nimport pydicom\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-07-27T02:20:46.425525Z","iopub.execute_input":"2023-07-27T02:20:46.426525Z","iopub.status.idle":"2023-07-27T02:20:46.602752Z","shell.execute_reply.started":"2023-07-27T02:20:46.426481Z","shell.execute_reply":"2023-07-27T02:20:46.601559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:25.755731Z","iopub.execute_input":"2023-07-27T02:21:25.756457Z","iopub.status.idle":"2023-07-27T02:21:25.809992Z","shell.execute_reply.started":"2023-07-27T02:21:25.756413Z","shell.execute_reply":"2023-07-27T02:21:25.808839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:21:29.894503Z","iopub.execute_input":"2023-07-27T02:21:29.894975Z","iopub.status.idle":"2023-07-27T02:21:29.922211Z","shell.execute_reply.started":"2023-07-27T02:21:29.894919Z","shell.execute_reply":"2023-07-27T02:21:29.920827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Explore the distribution of each injury type and degree in the train.csv file\n# injury_types = ['bowel', 'extravasation', 'kidney', 'liver', 'spleen']\n# injury_degrees = ['healthy', 'low', 'high']\n\n# for injury_type in injury_types:\n#     for injury_degree in injury_degrees:\n#         column_name = f'{injury_type}_{injury_degree}'\n#         counts = train_df[column_name].value_counts()\n#         print(f'\\n{injury_type} - {injury_degree} counts:')\n#         print(counts)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:25:52.581143Z","iopub.execute_input":"2023-07-27T02:25:52.58156Z","iopub.status.idle":"2023-07-27T02:25:52.588045Z","shell.execute_reply.started":"2023-07-27T02:25:52.581529Z","shell.execute_reply":"2023-07-27T02:25:52.586672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Explore the train_series_meta.csv file containing scan information\nseries_meta_df = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train_series_meta.csv')\nseries_meta_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:22:50.536882Z","iopub.execute_input":"2023-07-27T02:22:50.538202Z","iopub.status.idle":"2023-07-27T02:22:50.559062Z","shell.execute_reply.started":"2023-07-27T02:22:50.538157Z","shell.execute_reply":"2023-07-27T02:22:50.557932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"series_meta_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:23:01.610428Z","iopub.execute_input":"2023-07-27T02:23:01.610896Z","iopub.status.idle":"2023-07-27T02:23:01.625686Z","shell.execute_reply.started":"2023-07-27T02:23:01.610856Z","shell.execute_reply":"2023-07-27T02:23:01.624281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualize a sample CT scan using DICOM images\ndef plot_dicom_image(image_path):\n    ds = pydicom.dcmread(image_path)\n    plt.imshow(ds.pixel_array, cmap=plt.cm.bone)\n    plt.axis('off')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:24:09.210452Z","iopub.execute_input":"2023-07-27T02:24:09.210927Z","iopub.status.idle":"2023-07-27T02:24:09.218909Z","shell.execute_reply.started":"2023-07-27T02:24:09.210892Z","shell.execute_reply":"2023-07-27T02:24:09.217292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_image_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\nplot_dicom_image(sample_image_path)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:25:37.962752Z","iopub.execute_input":"2023-07-27T02:25:37.963291Z","iopub.status.idle":"2023-07-27T02:25:38.247384Z","shell.execute_reply.started":"2023-07-27T02:25:37.963251Z","shell.execute_reply":"2023-07-27T02:25:38.245622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_level_labels_df = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/image_level_labels.csv')\nimage_level_labels_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:28:16.16211Z","iopub.execute_input":"2023-07-27T02:28:16.163627Z","iopub.status.idle":"2023-07-27T02:28:16.198141Z","shell.execute_reply.started":"2023-07-27T02:28:16.163587Z","shell.execute_reply":"2023-07-27T02:28:16.196801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_level_labels_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:28:25.140843Z","iopub.execute_input":"2023-07-27T02:28:25.141246Z","iopub.status.idle":"2023-07-27T02:28:25.160249Z","shell.execute_reply.started":"2023-07-27T02:28:25.141215Z","shell.execute_reply":"2023-07-27T02:28:25.158681Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualize a sample CT scan with pixel-level annotations (optional: use it if you have loaded segmentations)\ndef plot_dicom_image_with_annotations(image_path, annotation_path):\n    ds = pydicom.dcmread(image_path)\n    plt.imshow(ds.pixel_array, cmap=plt.cm.bone)\n    \n    # Assuming the path to a sample annotation from segmentations is 'segmentations/series_id.nii.gz'\n    annotation_path = 'segmentations/series_id.nii.gz'\n    # Load the annotation using the appropriate library (e.g., nibabel)\n    # annotation_data = load_annotation(annotation_path)\n    \n    # Plot the annotations over the CT scan\n    # plt.imshow(annotation_data, alpha=0.3, cmap='jet')  # Adjust alpha and cmap as needed\n    \n    plt.axis('off')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:28:41.538379Z","iopub.execute_input":"2023-07-27T02:28:41.538784Z","iopub.status.idle":"2023-07-27T02:28:41.545642Z","shell.execute_reply.started":"2023-07-27T02:28:41.538752Z","shell.execute_reply":"2023-07-27T02:28:41.544323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sample_series_id = series_meta_df['21057'].iloc[0]\n# sample_image_path = f'/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/{sample_series_id}/1001.dcm'\n# plot_dicom_image_with_annotations(sample_image_path)","metadata":{"execution":{"iopub.status.busy":"2023-07-27T02:33:07.982112Z","iopub.execute_input":"2023-07-27T02:33:07.982581Z","iopub.status.idle":"2023-07-27T02:33:08.123497Z","shell.execute_reply.started":"2023-07-27T02:33:07.982548Z","shell.execute_reply":"2023-07-27T02:33:08.122089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}