{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-output":false},"cell_type":"code","source":"import os\nimport numpy as np # linear algebra\n\nimport matplotlib.pyplot as plt\nimport pydicom\n\nimport pandas as pd","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Utils function"},{"metadata":{"trusted":true},"cell_type":"code","source":"def plot_pixel_array(image, figsize=(10,10)):\n    '''\n        param: \n            - image: np.array\n    '''\n    plt.figure(figsize=figsize)\n    plt.imshow(image, cmap=plt.cm.bone)\n    plt.show()\n    \ndef show_dcm_info(patientImg):\n    '''\n        param: \n            - patientImg: header data of dicom file.\n    '''\n    print(\"File Path:\", filePath)\n    print(\"Patient's Gender :\", patientImg.PatientSex)\n    \n    if 'PixelData' in patientImg:\n        rows = int(patientImg.Rows)\n        cols = int(patientImg.Columns)\n        print(\"Image size : {rows:d} x {cols:d}, {size:d} bytes\".format(\n            rows=rows, cols=cols, size=len(patientImg.PixelData)))\n        # Some patient have no pixel spacing value\n        if 'PixelSpacing' in patientImg:\n            print(\"Pixel spacing :\", patientImg.PixelSpacing)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"DIR = '/kaggle/input/vinbigdata-chest-xray-abnormalities-detection'\ntrainPath: list = [(DIR + '/train/' + x) for x in os.listdir(DIR + '/train')]\ntestPath: list = [(DIR + '/test/' + x) for x in os.listdir(DIR + '/test')]\nprint(os.listdir(DIR))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Show information of dataset"},{"metadata":{"trusted":true},"cell_type":"code","source":"sampleId: int = np.random.randint(0, len(trainPath))\ndicom_info = pydicom.dcmread(trainPath[sampleId])\ndicom_array = dicom_info.pixel_array\n\nprint('the number of train set: {}'.format(len(trainPath)))\nprint('the number of test set: {}'.format(len(testPath)))\nprint('Patient #{}'.format(sampleId))\nprint('Type of image:', type(dicom_array))\nprint('Shape of image:', dicom_array.shape)\nplt.figure(figsize=(7, 7))\nplt.imshow(dicom_array, cmap=plt.cm.bone)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train = pd.read_csv(DIR + \"/train.csv\")\nprint('Shape of file csv: {}'.format(df_train.shape))\nprint('Colume name csv: {}'.format(df_train.columns))\nprint(df_train.head(20))\nprint(df_train['image_id'][0])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Show some patient information"},{"metadata":{"trusted":true},"cell_type":"code","source":"i = 1\nnum_to_plot = 2\nfor filePath in trainPath:\n    data_info = pydicom.dcmread(filePath)\n    show_dcm_info(data_info)\n    plot_pixel_array(data_info.pixel_array, (5,5))\n    if i >= num_to_plot:\n        break\n    i += 1","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}