{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport cv2\nfrom tqdm import tqdm_notebook as tqdm\nimport pydicom as dcm","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def extract_DICOM_attributes(folder):\n    images = list(os.listdir(os.path.join(PATH, folder)))\n    df = pd.DataFrame()\n    for image in images:\n        image_name = image.split(\".\")[0]\n        dicom_file_path = os.path.join(PATH,folder,image)\n        dicom_file_dataset = dcm.read_file(dicom_file_path)\n        Patient_ID = dicom_file_dataset.PatientID\n        study_date = dicom_file_dataset.StudyDate\n        modality = dicom_file_dataset.Modality\n        age = dicom_file_dataset.PatientAge\n        sex = dicom_file_dataset.PatientSex\n        body_part_examined = dicom_file_dataset.BodyPartExamined\n        Samples_Per_Pixel = dicom_file_dataset.SamplesPerPixel\n        Bits_Allocated = dicom_file_dataset.BitsAllocated\n        Bits_Stored = dicom_file_dataset.BitsStored\n        High_Bit = dicom_file_dataset.HighBit\n        patient_orientation = dicom_file_dataset.PatientOrientation\n        photometric_interpretation = dicom_file_dataset.PhotometricInterpretation\n        rows = dicom_file_dataset.Rows\n        columns = dicom_file_dataset.Columns\n        Pixel_Representation = dicom_file_dataset.PixelRepresentation\n        Burned_In_Annotation = dicom_file_dataset.BurnedInAnnotation\n        Lossy_Image_Compression = dicom_file_dataset.LossyImageCompression\n        df = df.append(pd.DataFrame({'image_name': image_name, 'image_path': dicom_file_path,'Patient_ID' : Patient_ID,\n                        'dcm_modality': modality,'dcm_study_date': study_date, 'age': age, 'sex': sex, 'dcm_body_part_examined': body_part_examined,\n                        'Samples_Per_Pixel' : Samples_Per_Pixel, 'Bits_Allocated' : Bits_Allocated, 'Bits_Stored' : Bits_Stored, 'High_Bit' : High_Bit,'dcm_patient_orientation': patient_orientation,\n                        'dcm_photometric_interpretation': photometric_interpretation,\n                        'dcm_rows': rows, 'dcm_columns': columns,'Pixel_Representation' : Pixel_Representation, 'Burned_In_Annotation' : Burned_In_Annotation, 'Lossy_Image_Compression' : Lossy_Image_Compression}, index=[0]))\n    return df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PATH = '/kaggle/input/siim-isic-melanoma-classification'\nfolder = 'train'\ndicom_image_properties=extract_DICOM_attributes(folder)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dicom_image_properties.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dicom_image_properties.to_csv('dicom_image_properties.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pydicom as dcm\nimport pylab","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ds=dcm.read_file('/kaggle/input/siim-isic-melanoma-classification/train/ISIC_0015719.dcm')\npylab.imshow(ds.pixel_array, cmap=pylab.cm.bone)\npylab.show()","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}