{
  "id": 154658,
  "title": "Extract data from DICOM files",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/154658",
  "author_name": "",
  "post_date": "2020-05-29T09:33:00.855181400Z",
  "votes": 10,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Here is a simple routine to extract data from DICOM files.  </p>\n\n<p>You can easily extend it to get more parameters.</p>\n\n<p>```\ndef 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        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        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</p>\n\n<pre><code>    df = df.append(pd.DataFrame({'image_name': image_name, \n                    'dcm_modality': modality,'dcm_study_date':study_date, 'dcm_age': age, 'dcm_sex': sex,\n                    'dcm_body_part_examined': body_part_examined,'dcm_patient_orientation': patient_orientation,\n                    'dcm_photometric_interpretation': photometric_interpretation,\n                    'dcm_rows': rows, 'dcm_columns': columns}, index=[0]))\nreturn df\n</code></pre>\n\n<p>```</p>",
  "messages": [
    {
      "id": "866308",
      "postDate": "05/29/2020 09:33:00",
      "content": "<p>Here is a simple routine to extract data from DICOM files.  </p>\n\n<p>You can easily extend it to get more parameters.</p>\n\n<p>```\ndef 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        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        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</p>\n\n<pre><code>    df = df.append(pd.DataFrame({'image_name': image_name, \n                    'dcm_modality': modality,'dcm_study_date':study_date, 'dcm_age': age, 'dcm_sex': sex,\n                    'dcm_body_part_examined': body_part_examined,'dcm_patient_orientation': patient_orientation,\n                    'dcm_photometric_interpretation': photometric_interpretation,\n                    'dcm_rows': rows, 'dcm_columns': columns}, index=[0]))\nreturn df\n</code></pre>\n\n<p>```</p>",
      "rawMarkdown": "Here is a simple routine to extract data from DICOM files.  \n\nYou can easily extend it to get more parameters.\n\n```\ndef 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        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        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             \n        df = df.append(pd.DataFrame({'image_name': image_name, \n                        'dcm_modality': modality,'dcm_study_date':study_date, 'dcm_age': age, 'dcm_sex': sex,\n                        'dcm_body_part_examined': body_part_examined,'dcm_patient_orientation': patient_orientation,\n                        'dcm_photometric_interpretation': photometric_interpretation,\n                        'dcm_rows': rows, 'dcm_columns': columns}, index=[0]))\n    return df\n```",
      "votes": null
    },
    {
      "id": "866426",
      "postDate": "05/29/2020 11:48:31",
      "content": "<p>sounds good.</p>",
      "rawMarkdown": "sounds good.",
      "votes": null
    },
    {
      "id": "935395",
      "postDate": "07/19/2020 11:03:05",
      "content": "<p>while calling the function it eats up almost all of the RAM available(16GB)....Any suggestions....</p>",
      "rawMarkdown": "while calling the function it eats up almost all of the RAM available(16GB)....Any suggestions....",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 866426,
      "author_name": "baiqii",
      "author_url": "",
      "post_date": "05/29/2020 11:48:31",
      "content": "<p>sounds good.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 935395,
      "author_name": "suntech",
      "author_url": "",
      "post_date": "07/19/2020 11:03:05",
      "content": "<p>while calling the function it eats up almost all of the RAM available(16GB)....Any suggestions....</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "866308": "Here is a simple routine to extract data from DICOM files.  \n\nYou can easily extend it to get more parameters.\n\n```\ndef 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        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        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             \n        df = df.append(pd.DataFrame({'image_name': image_name, \n                        'dcm_modality': modality,'dcm_study_date':study_date, 'dcm_age': age, 'dcm_sex': sex,\n                        'dcm_body_part_examined': body_part_examined,'dcm_patient_orientation': patient_orientation,\n                        'dcm_photometric_interpretation': photometric_interpretation,\n                        'dcm_rows': rows, 'dcm_columns': columns}, index=[0]))\n    return df\n```",
    "866426": "sounds good.",
    "935395": "while calling the function it eats up almost all of the RAM available(16GB)....Any suggestions...."
  },
  "source": "meta"
}