{
  "id": 369874,
  "title": "Convert dcm extension images into jpg format.",
  "url": "/competitions/rsna-pneumonia-detection-challenge/discussion/369874",
  "author_name": "Selvin Macwan",
  "post_date": "2022-12-01T16:50:39.672000",
  "votes": 1,
  "comment_count": 0,
  "views": 0,
  "content": "<p><strong>pip install pydicom</strong>             # install pydicom library to read dcm extension images</p>\n<p><strong>import pydicom as dicom</strong></p>\n<p><strong>import numpy as np</strong></p>\n<p><strong>import cv2</strong></p>\n<p><strong>ds = dicom.dcmread('image path')</strong>   # read dcm extension image</p>\n<p><strong>img = np.asarray(ds.pixel_array)</strong>       # shape = (height, width)</p>\n<p><strong>img = np.expand_dims(img, axis=0)</strong>    #shape = (1,height, width)</p>\n<p><strong>img = np.moveaxis(img, -1, 0)</strong>       # shape = (height, 1, width)</p>\n<p><strong>img = np.moveaxis(img, -1, 0)</strong>      # shape = (height, width, 1) -&gt; gray scale image array (1 channel)</p>\n<p><strong>img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)</strong>       # shape = (height, width, 3)  -&gt; color image array(3 channel)</p>\n<p><strong>cv2.imwrite('output.jpg',img)</strong>       # save image in jpg format </p>",
  "messages": [
    {
      "id": 2051854,
      "postDate": "2022-12-01T16:50:39.673Z",
      "content": "<p><strong>pip install pydicom</strong>             # install pydicom library to read dcm extension images</p>\n<p><strong>import pydicom as dicom</strong></p>\n<p><strong>import numpy as np</strong></p>\n<p><strong>import cv2</strong></p>\n<p><strong>ds = dicom.dcmread('image path')</strong>   # read dcm extension image</p>\n<p><strong>img = np.asarray(ds.pixel_array)</strong>       # shape = (height, width)</p>\n<p><strong>img = np.expand_dims(img, axis=0)</strong>    #shape = (1,height, width)</p>\n<p><strong>img = np.moveaxis(img, -1, 0)</strong>       # shape = (height, 1, width)</p>\n<p><strong>img = np.moveaxis(img, -1, 0)</strong>      # shape = (height, width, 1) -&gt; gray scale image array (1 channel)</p>\n<p><strong>img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)</strong>       # shape = (height, width, 3)  -&gt; color image array(3 channel)</p>\n<p><strong>cv2.imwrite('output.jpg',img)</strong>       # save image in jpg format </p>",
      "rawMarkdown": "**pip install pydicom**             # install pydicom library to read dcm extension images\n\n**import pydicom as dicom**\n\n**import numpy as np**\n\n**import cv2**\n\n**ds = dicom.dcmread('image path')**   # read dcm extension image\n\n**img = np.asarray(ds.pixel_array)**       # shape = (height, width)\n\n**img = np.expand_dims(img, axis=0)**    #shape = (1,height, width)\n\n**img = np.moveaxis(img, -1, 0)**       # shape = (height, 1, width)\n\n**img = np.moveaxis(img, -1, 0)**      # shape = (height, width, 1) -> gray scale image array (1 channel)\n\n**img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)**       # shape = (height, width, 3)  -> color image array(3 channel)\n\n**cv2.imwrite('output.jpg',img)**       # save image in jpg format ",
      "votes": 1
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2051854": "**pip install pydicom**             # install pydicom library to read dcm extension images\n\n**import pydicom as dicom**\n\n**import numpy as np**\n\n**import cv2**\n\n**ds = dicom.dcmread('image path')**   # read dcm extension image\n\n**img = np.asarray(ds.pixel_array)**       # shape = (height, width)\n\n**img = np.expand_dims(img, axis=0)**    #shape = (1,height, width)\n\n**img = np.moveaxis(img, -1, 0)**       # shape = (height, 1, width)\n\n**img = np.moveaxis(img, -1, 0)**      # shape = (height, width, 1) -> gray scale image array (1 channel)\n\n**img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)**       # shape = (height, width, 3)  -> color image array(3 channel)\n\n**cv2.imwrite('output.jpg',img)**       # save image in jpg format "
  }
}