{
  "id": 18036,
  "title": "dcm2bmp",
  "url": "/competitions/second-annual-data-science-bowl/discussion/18036",
  "author_name": "",
  "post_date": "2015-12-20T05:26:57.400Z",
  "votes": 2,
  "comment_count": 2,
  "views": 798,
  "content": "<p>The following bash script will convert all dcm files to bmp files using ImageMagick if you don't want to deal with the DICOM format.  Just run it in the directory you unzipped your data sets into.  If using Ubuntu you can install ImageMagick with:</p>\n\n<pre><code>sudo apt-get install imagemagick\n</code></pre>\n\n<p>If you prefer a format other than bmp then just change the extension in the script appropriately.  Also, it works by putting the bmp (an uncompressed format) file alongside the dcm file so it will use quite a bit of space.  After running this on both datasets I ended up with 129G.</p>\n\n<pre><code>#!/bin/bash                                                                                                                                        \nfor dcm_name in $(find . -name '*.dcm')\n    do\n        bmp_name=`echo ${dcm_name} | sed 's/dcm$/bmp/'`\n        echo convert ${dcm_name} ${bmp_name}\n        convert ${dcm_name} ${bmp_name}\n        retval=$?\n    if [[ $retval != 0 ]]\n        then\n            echo &quot;Error converting ${dcm_name} (retval=${retval})&quot;\n        exit 1\n    fi\ndone\nexit 0\n</code></pre>",
  "messages": [
    {
      "id": "102170",
      "postDate": "12/20/2015 05:26:57",
      "content": "<p>The following bash script will convert all dcm files to bmp files using ImageMagick if you don't want to deal with the DICOM format.  Just run it in the directory you unzipped your data sets into.  If using Ubuntu you can install ImageMagick with:</p>\n\n<pre><code>sudo apt-get install imagemagick\n</code></pre>\n\n<p>If you prefer a format other than bmp then just change the extension in the script appropriately.  Also, it works by putting the bmp (an uncompressed format) file alongside the dcm file so it will use quite a bit of space.  After running this on both datasets I ended up with 129G.</p>\n\n<pre><code>#!/bin/bash                                                                                                                                        \nfor dcm_name in $(find . -name '*.dcm')\n    do\n        bmp_name=`echo ${dcm_name} | sed 's/dcm$/bmp/'`\n        echo convert ${dcm_name} ${bmp_name}\n        convert ${dcm_name} ${bmp_name}\n        retval=$?\n    if [[ $retval != 0 ]]\n        then\n            echo &quot;Error converting ${dcm_name} (retval=${retval})&quot;\n        exit 1\n    fi\ndone\nexit 0\n</code></pre>",
      "rawMarkdown": "The following bash script will convert all dcm files to bmp files using ImageMagick if you don't want to deal with the DICOM format.  Just run it in the directory you unzipped your data sets into.  If using Ubuntu you can install ImageMagick with:\r\n\r\n    sudo apt-get install imagemagick\r\n\r\nIf you prefer a format other than bmp then just change the extension in the script appropriately.  Also, it works by putting the bmp (an uncompressed format) file alongside the dcm file so it will use quite a bit of space.  After running this on both datasets I ended up with 129G.\r\n\r\n    #!/bin/bash                                                                                                                                        \r\n    for dcm_name in $(find . -name '*.dcm')\r\n    do\r\n        bmp_name=`echo ${dcm_name} | sed 's/dcm$/bmp/'`\r\n        echo convert ${dcm_name} ${bmp_name}\r\n        convert ${dcm_name} ${bmp_name}\r\n        retval=$?\r\n        if [[ $retval != 0 ]]\r\n        then\r\n            echo \"Error converting ${dcm_name} (retval=${retval})\"\r\n            exit 1\r\n        fi\r\n    done\r\n    exit 0",
      "votes": null
    },
    {
      "id": "102174",
      "postDate": "12/20/2015 06:08:49",
      "content": "<p>This will strip out all metadata however (e.g. slice distances) so it's mainly useful for poking around and looking at the images early on.</p>",
      "rawMarkdown": "This will strip out all metadata however (e.g. slice distances) so it's mainly useful for poking around and looking at the images early on.",
      "votes": null
    },
    {
      "id": "102973",
      "postDate": "12/28/2015 05:56:35",
      "content": "<p>Thanks nice one! I have used similar script but with mogrify. If you need  metadata (or dicom tags?) I wrote small application to extract all available data into a csv file in a structured way. I just skipped <strong><em>ReferencedImageSequence</em></strong> column because few images doesnt have this info and the value is same. Runs on single thread, its using <a href=\"http://www.pixelmed.com/\">http://www.pixelmed.com/</a> java toolkit library which has BSD license. To run application locate the jar file:</p>\n\n<pre><code>java -jar DicomParser.jar &quot;PATH_HERE/heart/train&quot;\n</code></pre>\n\n<p>I can commit into my github this weekend but now I am going to work:) Maybe it will help someone. </p>",
      "rawMarkdown": "Thanks nice one! I have used similar script but with mogrify. If you need  metadata (or dicom tags?) I wrote small application to extract all available data into a csv file in a structured way. I just skipped ***ReferencedImageSequence*** column because few images doesnt have this info and the value is same. Runs on single thread, its using http://www.pixelmed.com/ java toolkit library which has BSD license. To run application locate the jar file:\r\n\r\n    java -jar DicomParser.jar \"PATH_HERE/heart/train\"\r\n\r\nI can commit into my github this weekend but now I am going to work:) Maybe it will help someone.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 102174,
      "author_name": "westonpace",
      "author_url": "",
      "post_date": "12/20/2015 06:08:49",
      "content": "<p>This will strip out all metadata however (e.g. slice distances) so it's mainly useful for poking around and looking at the images early on.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 102973,
      "author_name": "hrgiger",
      "author_url": "",
      "post_date": "12/28/2015 05:56:35",
      "content": "<p>Thanks nice one! I have used similar script but with mogrify. If you need  metadata (or dicom tags?) I wrote small application to extract all available data into a csv file in a structured way. I just skipped <strong><em>ReferencedImageSequence</em></strong> column because few images doesnt have this info and the value is same. Runs on single thread, its using <a href=\"http://www.pixelmed.com/\">http://www.pixelmed.com/</a> java toolkit library which has BSD license. To run application locate the jar file:</p>\n\n<pre><code>java -jar DicomParser.jar &quot;PATH_HERE/heart/train&quot;\n</code></pre>\n\n<p>I can commit into my github this weekend but now I am going to work:) Maybe it will help someone. </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "102170": "The following bash script will convert all dcm files to bmp files using ImageMagick if you don't want to deal with the DICOM format.  Just run it in the directory you unzipped your data sets into.  If using Ubuntu you can install ImageMagick with:\r\n\r\n    sudo apt-get install imagemagick\r\n\r\nIf you prefer a format other than bmp then just change the extension in the script appropriately.  Also, it works by putting the bmp (an uncompressed format) file alongside the dcm file so it will use quite a bit of space.  After running this on both datasets I ended up with 129G.\r\n\r\n    #!/bin/bash                                                                                                                                        \r\n    for dcm_name in $(find . -name '*.dcm')\r\n    do\r\n        bmp_name=`echo ${dcm_name} | sed 's/dcm$/bmp/'`\r\n        echo convert ${dcm_name} ${bmp_name}\r\n        convert ${dcm_name} ${bmp_name}\r\n        retval=$?\r\n        if [[ $retval != 0 ]]\r\n        then\r\n            echo \"Error converting ${dcm_name} (retval=${retval})\"\r\n            exit 1\r\n        fi\r\n    done\r\n    exit 0",
    "102174": "This will strip out all metadata however (e.g. slice distances) so it's mainly useful for poking around and looking at the images early on.",
    "102973": "Thanks nice one! I have used similar script but with mogrify. If you need  metadata (or dicom tags?) I wrote small application to extract all available data into a csv file in a structured way. I just skipped ***ReferencedImageSequence*** column because few images doesnt have this info and the value is same. Runs on single thread, its using http://www.pixelmed.com/ java toolkit library which has BSD license. To run application locate the jar file:\r\n\r\n    java -jar DicomParser.jar \"PATH_HERE/heart/train\"\r\n\r\nI can commit into my github this weekend but now I am going to work:) Maybe it will help someone."
  },
  "source": "meta"
}