title: Getting image from dicom .DCM file in node.js
body: <p>I would like to generate a thumbnail image from a .dcm file (Dicom) in node.js.</p>
  
  <p>So far I've found a node modules called <a href="https://i.stack.imgur.com/OPghm.png" rel="nofollow noreferrer"><code>dicom-parser</code></a> that extracts the metadata from a dcm file.</p>
  
  <p>My test case :</p>
  
  <pre><code>var dicom = require('dicom-parser');
  var fs = require('fs');
  
  var dicomFileAsBuffer = fs.readFileSync('./FullPano.dcm');
  
  var dataSet = dicom.parseDicom(dicomFileAsBuffer);
  
  var pixelData = new Uint8Array(dataSet.byteArray.buffer, 
                                  dataSet.elements.x00880200.items[0].dataSet.elements.x7fe00010.dataOffset, 
                                  dataSet.elements.x00880200.items[0].dataSet.elements.x7fe00010.length);
  
  fs.writeFileSync('test5.jpg', pixelData); // &lt;----- not working :'(
  </code></pre>
  
  <p>To help you help me debug, here is the <code>dataSet.elements.x00880200</code> object :</p>
  
  <p><a href="https://i.stack.imgur.com/OPghm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OPghm.png" alt="dataSet.elements.x00880200"></a></p>
  
  <p>But the pixelData stored in the tag x00880200 -> x7fe00010 is not in a standard format, either jpeg, jpg, png... The idea here is to get the thumbnail of a dcm image directly from a file, on the fly, server-side in nodejs.</p>
  
  <p>From the <a href="http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.1.1.6" rel="nofollow noreferrer">dicom doc</a> (see below), the tag 0088,0200 holds the data for the icon, aka thumbnail.</p>
  
  <blockquote>
    <p>Icon Image Sequence</p>
    
    <p>(0088,0200)</p>
    
    <p>3</p>
    
    <p>This icon image is representative of the Image.</p>
    
    <p>Only a single Item is permitted in this Sequence.</p>
  </blockquote>
  
  <p>I've come around the <code>cornerstone</code> libs : <a href="https://github.com/cornerstonejs/cornerstone/issues/246" rel="nofollow noreferrer"><code>cornerstone-js</code></a> and <a href="https://github.com/cornerstonejs/cornerstone/issues/246" rel="nofollow noreferrer"><code>wado-image-loader</code></a>. But neither are working in a node.js environment (made an <a href="https://github.com/cornerstonejs/cornerstone/issues/246" rel="nofollow noreferrer">issue about that</a>). These libs can generate the "main" image of a dcm, but only once the dcm file is loaded on the cliend-side, in js. My requirement is to do that in nodejs, for the icon/thumbnail.</p>