python dicom -- getting pixel value from dicom file
<p>I was trying to get the pixelvalues of a dicom file in python using the dicom library.</p>

<p>But it returns only an array with zeros. </p>

<p>My code was like this:</p>

<pre><code>import dicom

import numpy 

ds=pydicom.read_file("sample.dcm")

print(ds.pixel_array)
</code></pre>

<p>and the results is</p>

<pre><code> [[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
</code></pre>

<p>Do you have any idea how to get the values of the pixels?</p>

<p>Thanks a lot in advance.</p>

<p>Andras</p>

<p>The code as written should work.  It is possible that the beginning and end of the array are truly zeros.</p>

<p>It is usually more meaningful to look at something in the middle of the image.</p>

<p>E.g.:</p>

<pre><code>midrow = ds.Rows // 2
midcol = ds.Columns // 2
print(ds.pixel_array[midrow-20:midrow+20, midcol-20:midcol+20])
</code></pre>

<p>If it is truly zeros everywhere, then that is either the true image or some kind of bug.  Perhaps reading with a dicom viewer can help if that hasn't been tried.</p>

python numpy pixel dicom