{"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":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# Plot dicom data\n\nThis is supersimple quick EDA--- just plot some dicom data!","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pydicom\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\nimport glob\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\ndef dicom2array(path, voi_lut=True, fix_monochrome=True):\n    # Original from: https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way\n    dicom = pydicom.read_file(path)\n    if voi_lut:\n        data = apply_voi_lut(dicom.pixel_array, dicom)\n    else:\n        data = dicom.pixel_array\n    if fix_monochrome and dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        data = np.amax(data) - data\n        \n    data = data - np.min(data)\n    data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n    return data\n\nimage_list = sorted(glob.glob('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/00002/FLAIR/*.dcm'))\nnum_cols = 5\nstart = 30\nend = 80\nf, ax = plt.subplots(nrows= 10, ncols= 5, figsize=(12, 24))\nfor index in range(start, end):\n    img = dicom2array(image_list[index])\n    index = index-start\n    i,j = index // num_cols, index % num_cols\n    ax[i, j].imshow(img, cmap=\"gray\")\n    ax[i, j].axis(\"off\")\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-14T07:05:32.104186Z","iopub.execute_input":"2021-07-14T07:05:32.104582Z","iopub.status.idle":"2021-07-14T07:05:36.82384Z","shell.execute_reply.started":"2021-07-14T07:05:32.104547Z","shell.execute_reply":"2021-07-14T07:05:36.822766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}