[vtkusers] how to get the gray value of all the pixel for a DICOM image

Liu_tj tjlp at netease.com
Wed Mar 9 12:06:46 EST 2016


Hi, VTK expert guys,

I want to make a statistic of gray value, so I need to get the gray value of all the pixels for a DICOM image. My code below can't get the gray value correctly. I use C# with Activiz. The scalar component should be 1 for the DICOM image.

int[] dims = new int[3];
dims = m_imageViewer.GetInput().GetDimensions();
int numComponents = m_imageViewer.GetInput().GetNumberOfScalarComponents(); //The scalar component is 1.
int numPoints = m_imageViewer.GetInput().GetNumberOfPoints();
string typestring = m_imageViewer.GetInput().GetScalarTypeAsString();
for (int z = 0; z < dims[2]; z++)
{
   for (int y = 0; y < dims[1]; y++)
   {
     for (int x = 0; x < dims[0]; x++)
     {
       System.IntPtr pixel = (m_imageViewer.GetInput().GetScalarPointer(x, y, z));
       int[] pixelvalue = new int[numComponents];
       Marshal.Copy(pixel, pixelvalue, 0, numComponents );
       ...
     }
   }
}

After Marshal.Copy(), the pixelvalue array store wrong value which is less greatly then the lower bound of GetScalarRange().

Any wrong code?

Thanks
Liu Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160310/5754e71b/attachment.html>


More information about the vtkusers mailing list