{"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 numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-07T17:05:09.246076Z","iopub.execute_input":"2023-08-07T17:05:09.246522Z","iopub.status.idle":"2023-08-07T17:05:09.253461Z","shell.execute_reply.started":"2023-08-07T17:05:09.246491Z","shell.execute_reply":"2023-08-07T17:05:09.25185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train_series_meta.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-07T16:57:33.717833Z","iopub.execute_input":"2023-08-07T16:57:33.718185Z","iopub.status.idle":"2023-08-07T16:57:33.744898Z","shell.execute_reply.started":"2023-08-07T16:57:33.718163Z","shell.execute_reply":"2023-08-07T16:57:33.743962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metadata","metadata":{"execution":{"iopub.status.busy":"2023-08-07T16:57:38.048905Z","iopub.execute_input":"2023-08-07T16:57:38.049323Z","iopub.status.idle":"2023-08-07T16:57:38.084081Z","shell.execute_reply.started":"2023-08-07T16:57:38.049293Z","shell.execute_reply":"2023-08-07T16:57:38.082821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-07T16:59:56.596538Z","iopub.execute_input":"2023-08-07T16:59:56.596995Z","iopub.status.idle":"2023-08-07T16:59:56.615084Z","shell.execute_reply.started":"2023-08-07T16:59:56.596964Z","shell.execute_reply":"2023-08-07T16:59:56.613567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:00:00.274273Z","iopub.execute_input":"2023-08-07T17:00:00.274779Z","iopub.status.idle":"2023-08-07T17:00:00.316094Z","shell.execute_reply.started":"2023-08-07T17:00:00.274715Z","shell.execute_reply":"2023-08-07T17:00:00.313766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv('/kaggle/input/rsna-2023-abdominal-trauma-detection/image_level_labels.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:15:12.999873Z","iopub.execute_input":"2023-08-07T17:15:13.000297Z","iopub.status.idle":"2023-08-07T17:15:13.021392Z","shell.execute_reply.started":"2023-08-07T17:15:13.000264Z","shell.execute_reply":"2023-08-07T17:15:13.020446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:15:35.845365Z","iopub.execute_input":"2023-08-07T17:15:35.846232Z","iopub.status.idle":"2023-08-07T17:15:35.85395Z","shell.execute_reply.started":"2023-08-07T17:15:35.846201Z","shell.execute_reply":"2023-08-07T17:15:35.851923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:15:49.176487Z","iopub.execute_input":"2023-08-07T17:15:49.176981Z","iopub.status.idle":"2023-08-07T17:15:49.190637Z","shell.execute_reply.started":"2023-08-07T17:15:49.176945Z","shell.execute_reply":"2023-08-07T17:15:49.188994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels.patient_id.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:16:09.280209Z","iopub.execute_input":"2023-08-07T17:16:09.280648Z","iopub.status.idle":"2023-08-07T17:16:09.296506Z","shell.execute_reply.started":"2023-08-07T17:16:09.280613Z","shell.execute_reply":"2023-08-07T17:16:09.294397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pydicom","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:02:28.616174Z","iopub.execute_input":"2023-08-07T17:02:28.616575Z","iopub.status.idle":"2023-08-07T17:02:39.846029Z","shell.execute_reply.started":"2023-08-07T17:02:28.616545Z","shell.execute_reply":"2023-08-07T17:02:39.845126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom as dc","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:02:40.249741Z","iopub.execute_input":"2023-08-07T17:02:40.250196Z","iopub.status.idle":"2023-08-07T17:02:40.399628Z","shell.execute_reply.started":"2023-08-07T17:02:40.250159Z","shell.execute_reply":"2023-08-07T17:02:40.398544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_to_dicom_files = \"/kaggle/input/rsna-2023-abdominal-trauma-detection/train_dicom_tags.parquet\"\n# Read the Parquet file into a DataFrame\ndf_dicom = pd.read_parquet(path_to_dicom_files)","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:18:42.441025Z","iopub.execute_input":"2023-08-07T17:18:42.441456Z","iopub.status.idle":"2023-08-07T17:18:47.066988Z","shell.execute_reply.started":"2023-08-07T17:18:42.441418Z","shell.execute_reply":"2023-08-07T17:18:47.065008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_dicom","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:18:52.515675Z","iopub.execute_input":"2023-08-07T17:18:52.516132Z","iopub.status.idle":"2023-08-07T17:18:53.658257Z","shell.execute_reply.started":"2023-08-07T17:18:52.516096Z","shell.execute_reply":"2023-08-07T17:18:53.657212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_to_dicom_files = \"/kaggle/input/rsna-2023-abdominal-trauma-detection/train_dicom_tags.parquet\"\n\ndicom_files = []\nfor dirName, subdirList, fileList in os.walk(path_to_dicom_files):\n    for filename in fileList:\n        dicom_files.append(os.path.join(dirName, filename))","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:03:46.087985Z","iopub.execute_input":"2023-08-07T17:03:46.088434Z","iopub.status.idle":"2023-08-07T17:03:46.097219Z","shell.execute_reply.started":"2023-08-07T17:03:46.088403Z","shell.execute_reply":"2023-08-07T17:03:46.095921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now you have a list of paths to your DICOM files in the 'dicom_files' list.","metadata":{}},{"cell_type":"code","source":"dicom_images = []\nfor file_path in dicom_files:\n    dicom_data = dc.dcmread(file_path)\n    dicom_images.append(dicom_data.pixel_array)","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:06:00.205456Z","iopub.execute_input":"2023-08-07T17:06:00.205952Z","iopub.status.idle":"2023-08-07T17:06:00.210432Z","shell.execute_reply.started":"2023-08-07T17:06:00.205924Z","shell.execute_reply":"2023-08-07T17:06:00.209621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"'dicom_images' now contains the pixel arrays of all the DICOM images in your dataset.","metadata":{}},{"cell_type":"code","source":"# Display one of the DICOM images using matplotlib\nplt.imshow(dicom_images[0], cmap=plt.cm.bone)\nplt.title(\"DICOM Image\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:06:03.141072Z","iopub.execute_input":"2023-08-07T17:06:03.141551Z","iopub.status.idle":"2023-08-07T17:06:03.181088Z","shell.execute_reply.started":"2023-08-07T17:06:03.141522Z","shell.execute_reply":"2023-08-07T17:06:03.178676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom_image","metadata":{"execution":{"iopub.status.busy":"2023-08-07T17:06:07.247072Z","iopub.execute_input":"2023-08-07T17:06:07.247527Z","iopub.status.idle":"2023-08-07T17:06:07.256554Z","shell.execute_reply.started":"2023-08-07T17:06:07.247487Z","shell.execute_reply":"2023-08-07T17:06:07.255032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}