{"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 torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.optim import lr_scheduler\nimport numpy as np\nimport torchvision\nfrom torchvision import datasets, models, transforms\nimport matplotlib.pyplot as plt\nfrom torch.utils.data import Dataset, DataLoader\nimport time\nimport os\nimport copy\nimport cv2\nimport pydicom\nfrom itertools import product\nimport pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-14T01:31:46.403682Z","iopub.execute_input":"2021-08-14T01:31:46.404121Z","iopub.status.idle":"2021-08-14T01:31:48.054496Z","shell.execute_reply.started":"2021-08-14T01:31:46.404064Z","shell.execute_reply":"2021-08-14T01:31:48.053322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"basePath = \"/kaggle/input\"\nrootFolder = f\"{basePath}/rsna-miccai-brain-tumor-radiogenomic-classification\"\ntrainFolder = rootFolder + \"/train\"\ntestFolder = rootFolder + \"/test\"\ntrainLabels = rootFolder + \"/train_labels.csv\"\ntypes=[\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\"]\nmodel_base_path = f\"{basePath}/2dvgg19pretrained/miccai-0-1065\"\noutputFolder = f\"/kaggle/working/\"","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.056045Z","iopub.execute_input":"2021-08-14T01:31:48.056370Z","iopub.status.idle":"2021-08-14T01:31:48.063517Z","shell.execute_reply.started":"2021-08-14T01:31:48.056340Z","shell.execute_reply":"2021-08-14T01:31:48.062445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(trainLabels, dtype=str)\ntrain_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.065904Z","iopub.execute_input":"2021-08-14T01:31:48.066426Z","iopub.status.idle":"2021-08-14T01:31:48.112368Z","shell.execute_reply.started":"2021-08-14T01:31:48.066369Z","shell.execute_reply":"2021-08-14T01:31:48.111434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.to_csv('/kaggle/working/test.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.115147Z","iopub.execute_input":"2021-08-14T01:31:48.115482Z","iopub.status.idle":"2021-08-14T01:31:48.124165Z","shell.execute_reply.started":"2021-08-14T01:31:48.115449Z","shell.execute_reply":"2021-08-14T01:31:48.123332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getChildNames(path):\n        return os.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.125233Z","iopub.execute_input":"2021-08-14T01:31:48.125643Z","iopub.status.idle":"2021-08-14T01:31:48.132261Z","shell.execute_reply.started":"2021-08-14T01:31:48.125613Z","shell.execute_reply":"2021-08-14T01:31:48.131279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getPathDataset(dsType, ):\n    \n    \n    pathDS = []\n    totalcases = 0\n    BratsIds = []\n    labels = []\n    if dsType == \"train\":\n        totalCases = train_df.shape[0]\n        BratsIds = train_df.BraTS21ID.values\n        labels = train_df.MGMT_value.values\n    elif dsType == \"test\":\n        BratsIds = [name for name in getChildNames(f\"{rootFolder}/{dsType}\")]\n        totalCases = len(BratsIds)\n        labels = [-1] * totalCases\n\n    for index in range(totalCases):\n        caseId = BratsIds[index]\n        label = labels[index]\n        for _type in types:\n        #pathDS[caseId][_type] = []\n            tmpFolderPath = f\"{rootFolder}/{dsType}/{caseId}/{_type}/\"\n            allFiles = getChildNames(tmpFolderPath)\n            allFiles = sorted(\n                  allFiles, \n                  key=lambda x: int(x[:-4].split(\"-\")[-1]),\n              )\n            allFiles = [(tmpFolderPath + name, caseId, label, _type) for name in allFiles]\n            pathDS += allFiles\n\n    pathDS = pd.DataFrame(pathDS, columns = [\"FilePath\",\"CaseId\",\"MGMT_Value\",\"Modality\"])\n    return pathDS","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.133657Z","iopub.execute_input":"2021-08-14T01:31:48.134057Z","iopub.status.idle":"2021-08-14T01:31:48.147793Z","shell.execute_reply.started":"2021-08-14T01:31:48.134026Z","shell.execute_reply":"2021-08-14T01:31:48.146415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_dicom(path):\n    dicom = pydicom.read_file(path)\n    data = dicom.pixel_array\n    \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","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.148992Z","iopub.execute_input":"2021-08-14T01:31:48.149320Z","iopub.status.idle":"2021-08-14T01:31:48.164412Z","shell.execute_reply.started":"2021-08-14T01:31:48.149290Z","shell.execute_reply":"2021-08-14T01:31:48.163648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainPathDS = getPathDataset(\"train\")","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:31:48.166375Z","iopub.execute_input":"2021-08-14T01:31:48.166758Z","iopub.status.idle":"2021-08-14T01:32:53.713446Z","shell.execute_reply.started":"2021-08-14T01:31:48.166731Z","shell.execute_reply":"2021-08-14T01:32:53.712164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testPathDS = getPathDataset(\"test\")","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:32:53.715443Z","iopub.execute_input":"2021-08-14T01:32:53.715771Z","iopub.status.idle":"2021-08-14T01:33:03.911135Z","shell.execute_reply.started":"2021-08-14T01:32:53.715739Z","shell.execute_reply":"2021-08-14T01:33:03.910349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testPathDS.head()","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:03.912368Z","iopub.execute_input":"2021-08-14T01:33:03.912960Z","iopub.status.idle":"2021-08-14T01:33:03.925620Z","shell.execute_reply.started":"2021-08-14T01:33:03.912917Z","shell.execute_reply":"2021-08-14T01:33:03.924623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainPathDS.to_csv(f\"{outputFolder}/trainPathDS.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:03.926821Z","iopub.execute_input":"2021-08-14T01:33:03.927125Z","iopub.status.idle":"2021-08-14T01:33:06.334611Z","shell.execute_reply.started":"2021-08-14T01:33:03.927072Z","shell.execute_reply":"2021-08-14T01:33:06.333491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3D slice Count","metadata":{}},{"cell_type":"code","source":"%%time\nslice_info_3d = []\n\ntotalCases = train_df.shape[0]\nBratsIds = train_df.BraTS21ID.values\nlabels = train_df.MGMT_value.values\n\n\nfor index in range(totalCases):\n    caseId = BratsIds[index]\n    label = labels[index]\n    for _type in types:\n    #pathDS[caseId][_type] = []\n        tmpFolderPath = f\"{rootFolder}/train/{caseId}/{_type}/\"\n        allFiles = getChildNames(tmpFolderPath)\n        \n        totalSlices = len(allFiles)\n        H,W = load_dicom(f\"{tmpFolderPath}/{allFiles[0]}\").shape\n        \n        slice_info_3d.append((caseId, label, _type, f\"{H}x{W}\", totalSlices, f\"{H}x{W}x{totalSlices}\"))\n        \nslice_info_3d_df = pd.DataFrame(slice_info_3d, columns = [\"BraTS21ID\", \"MGMT_Value\",\"Modality\",\"2D Shape\",\"totalSlices\", \"FileShape\"])","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:06.335922Z","iopub.execute_input":"2021-08-14T01:33:06.336281Z","iopub.status.idle":"2021-08-14T01:33:28.877256Z","shell.execute_reply.started":"2021-08-14T01:33:06.336249Z","shell.execute_reply":"2021-08-14T01:33:28.876013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df.totalSlices.value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:28.880331Z","iopub.execute_input":"2021-08-14T01:33:28.880626Z","iopub.status.idle":"2021-08-14T01:33:28.891418Z","shell.execute_reply.started":"2021-08-14T01:33:28.880598Z","shell.execute_reply":"2021-08-14T01:33:28.890272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df.totalSlices.value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:28.892748Z","iopub.execute_input":"2021-08-14T01:33:28.893099Z","iopub.status.idle":"2021-08-14T01:33:28.914284Z","shell.execute_reply.started":"2021-08-14T01:33:28.893044Z","shell.execute_reply":"2021-08-14T01:33:28.912977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df.to_csv(\"slice_info_3d.csv\",index = False)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:28.915536Z","iopub.execute_input":"2021-08-14T01:33:28.915829Z","iopub.status.idle":"2021-08-14T01:33:28.937382Z","shell.execute_reply.started":"2021-08-14T01:33:28.915802Z","shell.execute_reply":"2021-08-14T01:33:28.936067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:28.938552Z","iopub.execute_input":"2021-08-14T01:33:28.938837Z","iopub.status.idle":"2021-08-14T01:33:28.958855Z","shell.execute_reply.started":"2021-08-14T01:33:28.938810Z","shell.execute_reply":"2021-08-14T01:33:28.957697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Check if patient information is present for all modalities","metadata":{"execution":{"iopub.status.busy":"2021-08-09T06:47:43.318866Z","iopub.execute_input":"2021-08-09T06:47:43.319229Z","iopub.status.idle":"2021-08-09T06:47:43.32291Z","shell.execute_reply.started":"2021-08-09T06:47:43.319184Z","shell.execute_reply":"2021-08-09T06:47:43.321939Z"}}},{"cell_type":"code","source":"tmp = trainPathDS.groupby(\"CaseId\")[\"Modality\"].agg([\"nunique\"]).reset_index()\ntmp.columns = [\"CaseId\", \"TotalMods\"]\ntmp[tmp.TotalMods < 4]","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:28.959832Z","iopub.execute_input":"2021-08-14T01:33:28.960119Z","iopub.status.idle":"2021-08-14T01:33:29.062820Z","shell.execute_reply.started":"2021-08-14T01:33:28.960064Z","shell.execute_reply":"2021-08-14T01:33:29.062112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp = testPathDS.groupby(\"CaseId\")[\"Modality\"].agg([\"nunique\"]).reset_index()\ntmp.columns = [\"CaseId\", \"TotalMods\"]\ntmp[tmp.TotalMods < 4]","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:29.064016Z","iopub.execute_input":"2021-08-14T01:33:29.064412Z","iopub.status.idle":"2021-08-14T01:33:29.091892Z","shell.execute_reply.started":"2021-08-14T01:33:29.064378Z","shell.execute_reply":"2021-08-14T01:33:29.090712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df[slice_info_3d_df.Modality == 'T1w'][\"totalSlices\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:29.093591Z","iopub.execute_input":"2021-08-14T01:33:29.093993Z","iopub.status.idle":"2021-08-14T01:33:29.105846Z","shell.execute_reply.started":"2021-08-14T01:33:29.093951Z","shell.execute_reply":"2021-08-14T01:33:29.104811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\ntmp = slice_info_3d_df[\"FileShape\"].value_counts().reset_index().sort_values(by = \"FileShape\", ascending = False)\ntmp= tmp.iloc[0:30]\n\n#plt.figure(figsize = ())\nsns.catplot(data = tmp, y = \"index\", x = \"FileShape\", kind=\"bar\", aspect = 2, height = 15)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:29.107631Z","iopub.execute_input":"2021-08-14T01:33:29.108183Z","iopub.status.idle":"2021-08-14T01:33:29.860767Z","shell.execute_reply.started":"2021-08-14T01:33:29.108031Z","shell.execute_reply":"2021-08-14T01:33:29.859781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"slice_info_3d_df","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:29.862091Z","iopub.execute_input":"2021-08-14T01:33:29.862396Z","iopub.status.idle":"2021-08-14T01:33:29.881388Z","shell.execute_reply.started":"2021-08-14T01:33:29.862367Z","shell.execute_reply":"2021-08-14T01:33:29.880398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\ntmp = slice_info_3d_df[\"2D Shape\"].value_counts().reset_index().sort_values(by = \"2D Shape\", ascending = False)\ntmp= tmp.iloc[0:30]\n\n#plt.figure(figsize = ())\nsns.catplot(data = tmp, y = \"index\", x = \"2D Shape\", kind=\"bar\", aspect = 2, height = 15)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:29.882803Z","iopub.execute_input":"2021-08-14T01:33:29.883135Z","iopub.status.idle":"2021-08-14T01:33:30.508036Z","shell.execute_reply.started":"2021-08-14T01:33:29.883106Z","shell.execute_reply":"2021-08-14T01:33:30.507025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import SimpleITK as sitk","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:30.511826Z","iopub.execute_input":"2021-08-14T01:33:30.512261Z","iopub.status.idle":"2021-08-14T01:33:31.017884Z","shell.execute_reply.started":"2021-08-14T01:33:30.512219Z","shell.execute_reply":"2021-08-14T01:33:31.016858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n\nreader = sitk.ImageSeriesReader()\nreader.LoadPrivateTagsOn()\n\nfor _type in types:\n    filenamesDICOM = reader.GetGDCMSeriesFileNames(f'{rootFolder}/train/00000/{_type}')\n    reader.SetFileNames(filenamesDICOM)\n    t1_sitk = reader.Execute()\n    sitk.WriteImage(t1_sitk,f'00000_{_type}.nii')","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:31.019292Z","iopub.execute_input":"2021-08-14T01:33:31.019574Z","iopub.status.idle":"2021-08-14T01:33:44.856040Z","shell.execute_reply.started":"2021-08-14T01:33:31.019548Z","shell.execute_reply":"2021-08-14T01:33:44.855296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from nilearn import plotting\n\nfor _type in types:\n    plotting.plot_stat_map(f'{outputFolder}/00000_{_type}.nii', bg_img=None)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:33:44.857303Z","iopub.execute_input":"2021-08-14T01:33:44.857836Z","iopub.status.idle":"2021-08-14T01:34:31.259106Z","shell.execute_reply.started":"2021-08-14T01:33:44.857799Z","shell.execute_reply":"2021-08-14T01:34:31.257916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Different orientation for same CaseId but different modality","metadata":{}},{"cell_type":"code","source":"from nilearn.image import resample_to_img, reorder_img\nimport nibabel as nib\n\nfor _type in types:\n    tmp = nib.load(f'{outputFolder}/00000_{_type}.nii')\n    print(tmp.shape)\n    tmp = reorder_img(tmp, resample=\"linear\")\n    print(tmp.shape)\n    #plotting.plot_stat_map(tmp, bg_img=None)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:34:31.260761Z","iopub.execute_input":"2021-08-14T01:34:31.261189Z","iopub.status.idle":"2021-08-14T01:34:31.280981Z","shell.execute_reply.started":"2021-08-14T01:34:31.261146Z","shell.execute_reply":"2021-08-14T01:34:31.279698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### resample_to_img\n- As the second modality is in RAS orientation, lets see if using second modality as base image Can I convert first image to second image\n- And then check whether it is in RAS or not","metadata":{}},{"cell_type":"code","source":"types","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:36:19.481459Z","iopub.execute_input":"2021-08-14T01:36:19.481857Z","iopub.status.idle":"2021-08-14T01:36:19.488994Z","shell.execute_reply.started":"2021-08-14T01:36:19.481823Z","shell.execute_reply":"2021-08-14T01:36:19.487750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from nilearn.image import resample_to_img, reorder_img\nimport nibabel as nib\n\nbase_image = nib.load(f'{outputFolder}/00000_T1w.nii')\nimage = nib.load(f'{outputFolder}/00000_FLAIR.nii')\n\nnew_img = resample_to_img(image, base_image, \"linear\")\nprint(new_img.shape)\n\nnew_img = reorder_img(new_img, resample=\"linear\")\nprint(new_img.shape)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:38:35.156553Z","iopub.execute_input":"2021-08-14T01:38:35.156970Z","iopub.status.idle":"2021-08-14T01:38:42.312105Z","shell.execute_reply.started":"2021-08-14T01:38:35.156939Z","shell.execute_reply":"2021-08-14T01:38:42.311047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Use dicom_nifty (but its not working at combine Slices\n- Wanted to check if dicom images can be converted to nifti without saving the images","metadata":{}},{"cell_type":"code","source":"'''import nibabel as nib\nimport dicom_numpy\nimport os\nimport numpy as np\n\npathtodicom = f'{rootFolder}/train/00000/FLAIR'\n# get list of dicom images from directory that make up the 3D image\ndicomlist = [pathtodicom + f for f in os.listdir(pathtodicom)]\n\n# load dicom volume\nvol, affine_LPS = dicom_numpy.combine_slices(dicomlist)\n\n# convert the LPS affine to RAS\naffine_RAS = np.diagflat([-1,-1,1,1]).dot(affine_LPS)\n\n# create nibabel nifti object\nniiimg = nib.Nifti1Image(vol, affine_RAS)\nprint(niiimg.shape)\n\nniiimg = reorder_img(niiimg, resample=\"linear\")\nprint(niiimg.shape)\n#nib.save(niiimg, '/path/to/save')\n'''","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:34:31.282396Z","iopub.execute_input":"2021-08-14T01:34:31.282810Z","iopub.status.idle":"2021-08-14T01:34:31.291247Z","shell.execute_reply.started":"2021-08-14T01:34:31.282767Z","shell.execute_reply":"2021-08-14T01:34:31.290162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Use dicom2nifti\n- Convert directory method removes the flexibility of providing destination file name","metadata":{}},{"cell_type":"code","source":"!pip install dicom2nifti","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import dicom2nifti\n\ndicom_directory = f'{rootFolder}/train/00000/FLAIR'\noutput_folder = f'{outputFolder}'\ndicom2nifti.convert_directory(dicom_directory, output_folder, compression=True, reorient=False)\n\n'''\nimport nibabel as nib\nnii = nib.load(output_folder)\nprint(nii.shape)\n\nfrom nilearn.image import reorder_img\n\nnii = reorder_img(nii, resample=\"linear\")\nprint(nii.shape)\n'''","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:34:31.292830Z","iopub.execute_input":"2021-08-14T01:34:31.293184Z","iopub.status.idle":"2021-08-14T01:34:31.368706Z","shell.execute_reply.started":"2021-08-14T01:34:31.293153Z","shell.execute_reply":"2021-08-14T01:34:31.367027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Manual sorting","metadata":{}},{"cell_type":"code","source":"reader = sitk.ImageSeriesReader()\nreader.LoadPrivateTagsOn()\n\n_type = 'FLAIR'\nallFiles = sorted(\n                  getChildNames(f'{rootFolder}/train/00000/{_type}'), \n                  key=lambda x: int(x[:-4].split(\"-\")[-1]),\n              )\n\n#filenamesDICOM = reader.GetGDCMSeriesFileNames(f'{rootFolder}/train/00000/{_type}')\nfilenamesDICOM = [f'{rootFolder}/train/00000/{_type}/{name}' for name in allFiles]\nreader.SetFileNames(filenamesDICOM)\nt1_sitk = reader.Execute()\nsitk.WriteImage(t1_sitk,f'00000_{_type}_ms.nii')\n\n\nfrom nilearn import plotting\nplotting.plot_stat_map(f'{outputFolder}/00000_FLAIR_ms.nii', bg_img=None)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:34:31.369809Z","iopub.status.idle":"2021-08-14T01:34:31.370245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Automatic sorting","metadata":{}},{"cell_type":"code","source":"reader = sitk.ImageSeriesReader()\nreader.LoadPrivateTagsOn()\n\n_type = 'FLAIR'\n\nfilenamesDICOM = reader.GetGDCMSeriesFileNames(f'{rootFolder}/train/00000/{_type}')\nreader.SetFileNames(filenamesDICOM)\nt1_sitk = reader.Execute()\nsitk.WriteImage(t1_sitk,f'00000_{_type}_as.nii')\n\n\nfrom nilearn import plotting\nplotting.plot_stat_map(f'{outputFolder}/00000_FLAIR_as.nii', bg_img=None)","metadata":{"execution":{"iopub.status.busy":"2021-08-14T01:34:31.371626Z","iopub.status.idle":"2021-08-14T01:34:31.372275Z"},"trusted":true},"execution_count":null,"outputs":[]}]}