{"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 os\nimport pydicom\nimport matplotlib.pyplot as plt\n\n# Directory containing your DICOM files\ndicom_directory = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations'\n\n# Get a list of all DICOM files in the directory\ndicom_paths = [os.path.join(dicom_directory, filename) for filename in os.listdir(dicom_directory) if filename.lower().endswith('.nii')]\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:42:57.437307Z","iopub.execute_input":"2023-08-05T19:42:57.438386Z","iopub.status.idle":"2023-08-05T19:42:57.444855Z","shell.execute_reply.started":"2023-08-05T19:42:57.438348Z","shell.execute_reply":"2023-08-05T19:42:57.443653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(dicom_paths)","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:42:57.781368Z","iopub.execute_input":"2023-08-05T19:42:57.781777Z","iopub.status.idle":"2023-08-05T19:42:57.787836Z","shell.execute_reply.started":"2023-08-05T19:42:57.78173Z","shell.execute_reply":"2023-08-05T19:42:57.786778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom_paths.sort()","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:43:21.307883Z","iopub.execute_input":"2023-08-05T19:43:21.308259Z","iopub.status.idle":"2023-08-05T19:43:21.313138Z","shell.execute_reply.started":"2023-08-05T19:43:21.30823Z","shell.execute_reply":"2023-08-05T19:43:21.312304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dicom_paths","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:43:26.354543Z","iopub.execute_input":"2023-08-05T19:43:26.354921Z","iopub.status.idle":"2023-08-05T19:43:26.36593Z","shell.execute_reply.started":"2023-08-05T19:43:26.354892Z","shell.execute_reply":"2023-08-05T19:43:26.364706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\n\n# Load the DICOM file\ntt = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\ntt = pydicom.dcmread(dicom_file_path)\n\n# Get the pixel data\npixel_data = tt.pixel_array\n\n# Display the image\nplt.imshow(pixel_data, cmap=plt.cm.gray)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(pixel_data)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pydicom\nimport matplotlib.pyplot as plt\n\n# Directory containing your DICOM files\ndicom_directory = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10005/18667'\n\n# Get a list of all DICOM files in the directory\ndicom_paths = [os.path.join(dicom_directory, filename) for filename in os.listdir(dicom_directory) if filename.lower().endswith('.dcm')]\n\nfor dicom_file_path in dicom_paths:\n    dicom_image = pydicom.dcmread(dicom_file_path)\n    pixel_data = dicom_image.pixel_array\n\n    plt.imshow(pixel_data, cmap=plt.cm.gray)\n    plt.axis('off')\n    plt.title('DICOM Image')\n    plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:41:27.96526Z","iopub.execute_input":"2023-08-05T19:41:27.965629Z","iopub.status.idle":"2023-08-05T19:41:45.21637Z","shell.execute_reply.started":"2023-08-05T19:41:27.965599Z","shell.execute_reply":"2023-08-05T19:41:45.214518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pydicom\nimport matplotlib.pyplot as plt\n\n# Directory containing your DICOM files\ndicom_directory = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057'\n\n# Get a list of all DICOM files in the directory\ndicom_paths = [os.path.join(dicom_directory, filename) for filename in os.listdir(dicom_directory) if filename.lower().endswith('.dcm')]\n\nfor dicom_file_path in dicom_paths:\n    dicom_image = pydicom.dcmread(dicom_file_path)\n    pixel_data = dicom_image.pixel_array\n\n    plt.imshow(pixel_data, cmap=plt.cm.gray)\n    plt.axis('off')\n    plt.title('DICOM Image')\n    plt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pydicom\nimport matplotlib.pyplot as plt\n\n# Directories containing your DICOM files\ndicom_directory_1 = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057'\ndicom_directory_2 = '/path_to_another_directory'  # Replace with the actual path\n\n# Get a list of all DICOM files in the directories\ndicom_paths_1 = [os.path.join(dicom_directory_1, filename) for filename in os.listdir(dicom_directory_1) if filename.lower().endswith('.dcm')]\ndicom_paths_2 = [os.path.join(dicom_directory_2, filename) for filename in os.listdir(dicom_directory_2) if filename.lower().endswith('.dcm')]\n\n# Loop through the DICOM files in both directories\nfor dicom_file_path_1, dicom_file_path_2 in zip(dicom_paths_1, dicom_paths_2):\n    dicom_image_1 = pydicom.dcmread(dicom_file_path_1)\n    dicom_image_2 = pydicom.dcmread(dicom_file_path_2)\n    \n    pixel_data_1 = dicom_image_1.pixel_array\n    pixel_data_2 = dicom_image_2.pixel_array\n\n    plt.figure(figsize=(10, 5))\n    \n    plt.subplot(1, 2, 1)\n    plt.imshow(pixel_data_1, cmap=plt.cm.gray)\n    plt.axis('off')\n    plt.title('DICOM Image - Folder 1')\n    \n    plt.subplot(1, 2, 2)\n    plt.imshow(pixel_data_2, cmap=plt.cm.gray)\n    plt.axis('off')\n    plt.title('DICOM Image - Folder 2')\n    \n    plt.tight_layout()\n    plt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\n\n# Load the DICOM file\ndicom_file_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/test_images/48843/62825/30.dcm'\ndicom_image = pydicom.dcmread(dicom_file_path)\n\n# Get the pixel data\npixel_data = dicom_image.pixel_array\n\n# Print the shape of the pixel data\nprint('Pixel Data Shape:', pixel_data.shape)\n\n# Display the image\nplt.imshow(pixel_data, cmap=plt.cm.gray)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\n\n# Load the DICOM file\ndicom_file_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/test_images/50046/24574/30.dcm'\ndicom_image = pydicom.dcmread(dicom_file_path)\n\n# Get the pixel data\npixel_data = dicom_image.pixel_array\n\n# Print the shape of the pixel data\nprint('Pixel Data Shape:', pixel_data.shape)\n\n# Display the image\nplt.imshow(pixel_data, cmap=plt.cm.gray)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\n\n# Load the DICOM file\ndicom_file_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\ndicom_image = pydicom.dcmread(dicom_file_path)\n\n# Get the pixel data\npixel_data = dicom_image.pixel_array\n\n# Print the shape of the pixel data\nprint('Pixel Data Shape:', pixel_data.shape)\n\n# Display the image\nplt.imshow(pixel_data, cmap=plt.cm.gray)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import nibabel as nib\nimport matplotlib.pyplot as plt\n\n# Path to your NIfTI file\nnifti_file_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/10000.nii'\n\n# Load the NIfTI file\nnifti_image = nib.load(nifti_file_path)\n\n# Get the data array and its shape\nnifti_data = nifti_image.get_fdata()\ndata_shape = nifti_data.shape\n\n# Display the data and shape\nplt.figure(figsize=(10, 4))\n\nplt.subplot(1, 2, 1)\nplt.imshow(nifti_data[:, :, data_shape[2] // 2], cmap='gray')\nplt.title('Slice at Z = {}'.format(data_shape[2] // 2))\nplt.axis('off')\n\nplt.subplot(1, 2, 2)\nplt.imshow(nifti_data[data_shape[0] // 2, :, :].T, cmap='gray')\nplt.title('Slice at X = {}'.format(data_shape[0] // 2))\nplt.axis('off')\n\nplt.tight_layout()\nplt.show()\n\nprint('Data Shape:', data_shape)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:44:29.865891Z","iopub.execute_input":"2023-08-05T19:44:29.866265Z","iopub.status.idle":"2023-08-05T19:44:33.143211Z","shell.execute_reply.started":"2023-08-05T19:44:29.866237Z","shell.execute_reply":"2023-08-05T19:44:33.141931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kk = 0\nfor kk in range(data_shape[2]):\n    print(\"First Train IMG\")\n    test_load = nib.load(\"/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/10000.nii\").get_fdata()\n    test_load.shape\n    test = test_load[:, :, kk]\n    plt.imshow(test)\n    plt.show()\n    print(kk)\n    print(\"First Train SEG\")\n#     test_load = nib.load(Y[0]).get_fdata()\n#     test_load.shape\n#     test = test_load[:,:,k[kk]]\n#     plt.imshow(test)\n#     plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T19:44:37.971721Z","iopub.execute_input":"2023-08-05T19:44:37.972102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_shape","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport matplotlib.pyplot as plt\n\n# Load the DICOM file\ndicom_file_path = '/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/10004/21057/1000.dcm'\ndicom_image = pydicom.dcmread(dicom_file_path)\n\n# Get the pixel data\npixel_data = dicom_image.pixel_array\n\n# Print the shape of the pixel data\nprint('Pixel Data Shape:', pixel_data.shape)\n\n# Display the image\nplt.imshow(pixel_data, cmap=plt.cm.gray)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kk = 0\nfor kk in range(data_shape[2]):\n    print(\"First Train IMG\")\n    test_load = nib.load(\"/kaggle/input/rsna-2023-abdominal-trauma-detection/segmentations/10000.nii\").get_fdata()\n    test_load.shape\n    test = test_load[:, :, kk]\n    plt.imshow(test, cmap='gray')\n    plt.show()\n    print(kk)\n    print(\"First Train SEG\")\n#     test_load = nib.load(Y[0]).get_fdata()\n#     test_load.shape\n#     test = test_load[:,:,k[kk]]\n#     plt.imshow(test)\n#     plt.show()\n    ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}