{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"# IMPORTANT TERMINOLOGY\n\n# VOI : value of interest\n# LUT : lookup table\n# MONOCHROME1 indicates that the greyscale ranges from bright to dark with ascending pixel values whereas,\n# MONOCHROME2 ranges from dark to bright with ascending pixel values\n# if window width reduces, contrast increases\n# if window center reduces, intensity increases","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O\nimport os","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_dir = \"/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train/\"\ntest_dir = \"/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/test/\"\n\ntrain_images = os.listdir(train_dir)\ntest_images = os.listdir(test_dir)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pydicom as pdcm\nimport matplotlib.pylab as plt\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\n\n# Read the first train image\nimage_path = train_dir + train_images[0]\ndicom_file = pdcm.dcmread(image_path)\n\n# apply_voi_lut function will return a numpy ndarray based on VOI LUT or windowing operation\n# if neither operation are present then dicom_file will be remain unchanged \nimg = apply_voi_lut(dicom_file.pixel_array, dicom_file)\n\n# if photometric interpretation of dicom file is MONOCHROME1\nif dicom_file.PhotometricInterpretation == \"MONOCHROME1\":\n    img = np.amax(img) - img\n\n# rescale pixel value between 0 to 255\nimg = (((img - np.min(img))/np.max(img))*255.0).astype(np.uint8)\n\nplt.figure(figsize = (12,12))\nplt.imshow(img, cmap=plt.cm.gray)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dicom_file","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"##### Reference:\n1. https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way\n2. https://stackoverflow.com/questions/15107381/image-type-in-dicom-standard-monochrome1-and-monochrome2#:~:text=2%20Answers&text=MONOCHROME1%20indicates%20that%20the%20greyscale,(0028%2C0004)%20attribute.\n3. https://web.archive.org/web/20150920230923/http://www.mccauslandcenter.sc.edu/mricro/dicom/index.html"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}