{"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":"","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","execution":{"iopub.status.busy":"2023-08-05T15:50:18.106047Z","iopub.execute_input":"2023-08-05T15:50:18.106545Z","iopub.status.idle":"2023-08-05T15:50:18.277682Z","shell.execute_reply.started":"2023-08-05T15:50:18.106505Z","shell.execute_reply":"2023-08-05T15:50:18.276648Z"},"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":"plt.imshow(pixel_data)\nplt.axis('off')  # Turn off axis labels\nplt.title('DICOM Image')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-08-05T15:50:24.523615Z","iopub.execute_input":"2023-08-05T15:50:24.524063Z","iopub.status.idle":"2023-08-05T15:50:24.692052Z","shell.execute_reply.started":"2023-08-05T15:50:24.524027Z","shell.execute_reply":"2023-08-05T15:50:24.690444Z"},"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":{"iopub.status.busy":"2023-08-05T15:51:19.711156Z","iopub.execute_input":"2023-08-05T15:51:19.71207Z","iopub.status.idle":"2023-08-05T15:51:23.113482Z","shell.execute_reply.started":"2023-08-05T15:51:19.712026Z","shell.execute_reply":"2023-08-05T15:51:23.111202Z"},"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":{"trusted":true},"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-05T15:19:31.873497Z","iopub.execute_input":"2023-08-05T15:19:31.873863Z","iopub.status.idle":"2023-08-05T15:19:32.331647Z","shell.execute_reply.started":"2023-08-05T15:19:31.873837Z","shell.execute_reply":"2023-08-05T15:19:32.330153Z"},"trusted":true},"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-05T15:22:52.199536Z","iopub.execute_input":"2023-08-05T15:22:52.200097Z","iopub.status.idle":"2023-08-05T15:25:35.753586Z","shell.execute_reply.started":"2023-08-05T15:22:52.200054Z","shell.execute_reply":"2023-08-05T15:25:35.751718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_shape[2]","metadata":{"execution":{"iopub.status.busy":"2023-08-05T15:21:43.294422Z","iopub.execute_input":"2023-08-05T15:21:43.295027Z","iopub.status.idle":"2023-08-05T15:21:43.306537Z","shell.execute_reply.started":"2023-08-05T15:21:43.294981Z","shell.execute_reply":"2023-08-05T15:21:43.303927Z"},"trusted":true},"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":{"iopub.status.busy":"2023-08-05T15:25:39.913127Z","iopub.execute_input":"2023-08-05T15:25:39.913597Z","iopub.status.idle":"2023-08-05T15:25:40.080154Z","shell.execute_reply.started":"2023-08-05T15:25:39.913556Z","shell.execute_reply":"2023-08-05T15:25:40.078449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}