{"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 glob\nimport os\nimport pydicom\nimport numpy as np\nfrom pydicom import dcmread\nimport matplotlib.pyplot as plt\nfolder = \"../input/rsna-miccai-brain-tumor-radiogenomic-classification/test/00161/\"\n\n\npaths = []\n\nfor i, t in enumerate((\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\"), 1):\n    t_paths = sorted(glob.glob(os.path.join(folder, t, \"*\")))\n    for file in t_paths:\n        paths.append(file)\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-28T15:20:07.549087Z","iopub.execute_input":"2022-03-28T15:20:07.549410Z","iopub.status.idle":"2022-03-28T15:20:07.565858Z","shell.execute_reply.started":"2022-03-28T15:20:07.549377Z","shell.execute_reply":"2022-03-28T15:20:07.564809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,10):\n    print(dcmread(paths[i]))","metadata":{"execution":{"iopub.status.busy":"2022-03-28T15:08:44.994585Z","iopub.execute_input":"2022-03-28T15:08:44.995200Z","iopub.status.idle":"2022-03-28T15:08:45.053328Z","shell.execute_reply.started":"2022-03-28T15:08:44.995161Z","shell.execute_reply":"2022-03-28T15:08:45.052593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_dcm(path):\n    dicom = pydicom.read_file(path)\n    data = dicom.pixel_array\n    data = data - np.min(data)\n    if np.max(data) != 0:\n        data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n    return data\n\n\ndef visualize_dcm():\n    plt.figure(figsize=(16, 5))\n    for i, t in enumerate((\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\"), 1):\n        t_paths = sorted(glob.glob(os.path.join(folder, t, \"*\")))\n        for file in t_paths:\n            data = load_dcm(file)\n            plt.subplot(1, 4, i)\n            plt.imshow(data, cmap=\"gray\")\n            plt.title(f\"{t}\", fontsize=16)\n            plt.axis(\"off\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T15:35:11.311081Z","iopub.execute_input":"2022-03-28T15:35:11.312080Z","iopub.status.idle":"2022-03-28T15:35:11.322636Z","shell.execute_reply.started":"2022-03-28T15:35:11.312029Z","shell.execute_reply":"2022-03-28T15:35:11.321708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualize_dcm()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T15:35:13.973826Z","iopub.execute_input":"2022-03-28T15:35:13.974143Z","iopub.status.idle":"2022-03-28T15:35:23.819848Z","shell.execute_reply.started":"2022-03-28T15:35:13.974111Z","shell.execute_reply":"2022-03-28T15:35:23.818684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}