{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport os\nimport pydicom\nfrom matplotlib import pyplot, cm\nfrom tqdm import tqdm\n# for dirname, _, filenames in os.walk('/kaggle/input'):","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"path = '/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!ls -lrth {path}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# reference for normalization: https://www.kaggle.com/raddar/convert-dicom-to-np-array-the-correct-way\n\ndef load_data(file_path, fix_monochrome = True):\n    \n    # read the dicom file\n    RefDs = pydicom.read_file(file_path)\n    \n    \n    # Load dimensions based on the number of rows, columns,\n    x_dim,y_dim = (int(RefDs.Rows), int(RefDs.Columns))\n    \n    # load pixel value\n    xray = RefDs.pixel_array\n    \n    # flip the pixels upside-down so that image is not inverted\n    xray = np.flipud(xray)\n    \n    if fix_monochrome and RefDs.PhotometricInterpretation == \"MONOCHROME1\":\n        xray = np.amax(xray) - xray\n        \n    xray = xray - np.min(xray)\n    xray = xray / np.max(xray)\n    xray = (xray * 255).astype(np.uint8)\n        \n    return xray, y_dim, x_dim\n    \n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def show_image(img_data, x_dim, y_dim):\n    pyplot.figure(dpi=100)\n    pyplot.axes().set_aspect('equal')\n    pyplot.set_cmap(pyplot.gray())\n    pyplot.pcolormesh(np.arange(x_dim),np.arange(y_dim),img_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# load and show tha image\nshow_image(*load_data(path + 'train/0108949daa13dc94634a7d650a05c0bb.dicom'))","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}