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

David Gobbi david.gobbi at gmail.com
Thu Mar 10 13:45:01 EST 2016


Hi Liu Peng,

The best way (most efficient) is to get the pixels as a vtkDataArray:

  dataArray = image.GetPointData().GetScalars();

Then you can use the data array methods to get the values, e.g.
  dataArray.GetNumberOfComponents();
  dataArray.GetNumberOfTuples();
  dataArray.GetTuple(i);

Or, if you know the data type, you can downcast the data array and
get the data in its native type.

 - David


On Wed, Mar 9, 2016 at 10:06 AM, Liu_tj <tjlp at netease.com> wrote:

> 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/3e0b0877/attachment.html>


More information about the vtkusers mailing list