{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":99552,"databundleVersionId":13190393,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### This notebook demonstrates how to handle the “Unable to decompress ‘JPEG Lossless…’” error when loading MRI T2 DICOM files with pydicom.\n\n- When INSTALL_DICOM_DECODERS = False, attempting to read certain MRI T2 images will raise:\n\n```bash\nUnable to decompress 'JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14 [Selection Value 1])' pixel data because all plugins are missing dependencies:  \n    gdcm - requires gdcm>=3.0.10  \n    pylibjpeg - requires pylibjpeg>=2.0 and pylibjpeg-libjpeg>=2.1  \n```\n\n- When INSTALL_DICOM_DECODERS = True, the notebook installs the pylibjpeg decoder stack, and the same files load successfully—but you must also downgrade NumPy to a 1.x release (pip install \"numpy<2.0\") for those plugins to work.","metadata":{}},{"cell_type":"code","source":"INSTALL_DICOM_DECODERS = True","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if INSTALL_DICOM_DECODERS:\n    # By installing the following packages, you’ll be able to load DICOM files that previously produced “Unable to decompress” errors.\n    !pip install --upgrade \\\n        pylibjpeg \\\n        pylibjpeg-libjpeg \\\n        pylibjpeg-openjpeg \\\n        imagecodecs\n    \n    !pip install --upgrade \"numpy<2.0\"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\n\nimport pydicom","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-03T13:51:00.799511Z","iopub.execute_input":"2025-08-03T13:51:00.799952Z","iopub.status.idle":"2025-08-03T13:51:02.024815Z","shell.execute_reply.started":"2025-08-03T13:51:00.799871Z","shell.execute_reply":"2025-08-03T13:51:02.023863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class CFG:\n    train_dir = \"/kaggle/input/rsna-intracranial-aneurysm-detection/train.csv\"\n    series_dir = \"/kaggle/input/rsna-intracranial-aneurysm-detection/series\"\n\n    # MRI T2\n    unsupported_examples = [\n        \"1.2.826.0.1.3680043.8.498.75712554178574230484227682423862727306/1.2.826.0.1.3680043.8.498.17519922285427694202954072250089631899.dcm\",\n        \"1.2.826.0.1.3680043.8.498.82768897201281605198635077495114055892/1.2.826.0.1.3680043.8.498.68945582683437992452043163207501090698.dcm\",\n        \"1.2.826.0.1.3680043.8.498.75712554178574230484227682423862727306/1.2.826.0.1.3680043.8.498.56324012072130108236035213375057123654.dcm\",\n    ]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-03T13:51:02.025815Z","iopub.execute_input":"2025-08-03T13:51:02.026207Z","iopub.status.idle":"2025-08-03T13:51:02.031917Z","shell.execute_reply.started":"2025-08-03T13:51:02.026183Z","shell.execute_reply":"2025-08-03T13:51:02.030731Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(CFG.train_dir)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-03T13:51:02.033726Z","iopub.execute_input":"2025-08-03T13:51:02.034002Z","iopub.status.idle":"2025-08-03T13:51:02.089765Z","shell.execute_reply.started":"2025-08-03T13:51:02.03398Z","shell.execute_reply":"2025-08-03T13:51:02.088516Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for path in CFG.unsupported_examples:\n    try:\n        file = pydicom.dcmread(f\"{CFG.series_dir}/{path}\")\n        img = file.pixel_array\n        plt.imshow(img)\n        plt.show()\n    except Exception as e:\n        print(e)\n        continue","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-03T13:51:02.090516Z","iopub.execute_input":"2025-08-03T13:51:02.090771Z","iopub.status.idle":"2025-08-03T13:51:02.125069Z","shell.execute_reply.started":"2025-08-03T13:51:02.09075Z","shell.execute_reply":"2025-08-03T13:51:02.124017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}