{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Checking Data Out\n\nIn this notebook I just want to check the data out and want to get back at my rusty skills."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ntraindf = pd.read_csv('/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train.csv')\ntraindf.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Now let's check first DICOM file. I will be using a library called [pydicom](https://github.com/pydicom/pydicom)."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"from pydicom import dcmread\nfrom pydicom.data import get_testdata_file\n\ndicomPath = f'/kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train/{traindf.iloc[0, 0]}.dicom'\ndicomFile = dcmread(dicomPath)\n\ndicomFile","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Now that we could read the dicom file, let's visualize the image. \n\nNote: here we could see a feature called 'Photometric Interpretation' is present for the X-Ray image. We might have to note this down to convert all dicoms to a single PI."},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nimageArr = dicomFile.pixel_array\nprint(f'Print image shape: {imageArr.shape}')\n\nplt.imshow(imageArr)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I don't know about the error what pillow_handler shows, however the program works! It might be possible that some dicom may seem as blank image, in my experience, to overcome these images we could normalize image array first."},{"metadata":{"trusted":true},"cell_type":"code","source":"imageArr = (imageArr - np.amin(imageArr)) / (np.amax(imageArr) - np.amin(imageArr))\nprint(f'max Value: {np.amax(imageArr)}\\nmin Value: {np.amin(imageArr)}')\n\nplt.imshow(imageArr)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Is it just me or the normalized image seemsa little bit clear? All of this aside, let me plan on what do on my next notebook for the competition:\n\n1. Add a Photometric Interpretation column to the dataframe.\n2. Convert all dicom to a single PI.\n3. Instead of using RCNN or other masking techniques, Use gradients to make bounding box.\n4. [optinal] Crop lungs out as much as possible.\n\nFor the time being I will first focus on predictions, then on bounding boxes."},{"metadata":{},"cell_type":"markdown","source":"Is there any class skewness?"},{"metadata":{"trusted":true},"cell_type":"code","source":"traindf.class_name.value_counts().plot(kind='bar')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"traindf.class_name.value_counts()","execution_count":null,"outputs":[]},{"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}