[vtkusers] why my computing gray scale histogram of DICOM files is different from mimics

Liu_tj tjlp at netease.com
Sun Aug 14 11:52:32 EDT 2016


Hi,

I try to get the grayscale of points in DICOM files and draw the histogram using .NET component, and what I get is different from the histogram of MIMICS. My C# code is as follow, the returned vtkLongArray stores the grayscale statistic result, value of element is the total number of the point whose gray scale value is equal to the array index:

public vtkLongArray GetGreyScaleStatisticsFromImageData(vtkImageData data, out long min_grey, out long max_grey)
{
            vtkImageExtractComponents extract = vtkImageExtractComponents.New();
            extract.SetInputData(data);
            extract.SetComponents(0);
            extract.Update();

            double[] scalarrange = extract.GetOutput().GetScalarRange();
            min_grey = (long)scalarrange[0];
            max_grey = (long)scalarrange[1];
            long size = (long)(scalarrange[1] - scalarrange[0]);
            vtkImageAccumulate histogram = vtkImageAccumulate.New();
            histogram.SetInputConnection(extract.GetOutputPort());
            histogram.SetComponentExtent((int)min_grey, (int)max_grey, 0, 0, 0, 0);
            histogram.SetComponentOrigin(0, 0, 0);
            histogram.SetComponentSpacing(1, 0, 0);
            histogram.SetIgnoreZero(1);
            histogram.Update();
            vtkLongArray count = vtkLongArray.New();
            count.SetNumberOfComponents(1);
            count.SetNumberOfTuples(size);
            IntPtr value = histogram.GetOutput().GetScalarPointer();
            string scalartype = histogram.GetOutput().GetScalarTypeAsString();
            int s = histogram.GetOutput().GetScalarSize();
            long[] managedValArray = new long[size];
            Marshal.Copy(value, managedValArray, 0, managedValArray.Length);
            for(int i=0; i<managedValArray.Length; i++)
            {
                count.SetTuple1(i, managedValArray[i]);
            }
            return count;
}

The images of my and MIMICS are attached.

Does any guys know that?

Thanks
Liu Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160814/e897e8ef/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my-histogram.png
Type: image/png
Size: 6781 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160814/e897e8ef/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: histogram-mimics.png
Type: image/png
Size: 35442 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160814/e897e8ef/attachment-0001.png>


More information about the vtkusers mailing list