[vtkusers] Byte array from a Dicom Image
Matias Montroull
matimontg at gmail.com
Tue Feb 4 20:23:20 EST 2014
Here's the answer to my stupid question..
Rescale Intercept is -1024 in my DICOM image, and RescaleSlope is 1. Then
following this rule:
Pixel(x,y) = Data(x, y) * Rescale Slope + Rescale Intercept
I get the 62512
On Sat, Jan 25, 2014 at 12:00 AM, Matias Montroull <matimontg at gmail.com>wrote:
> Why the vtkUnsignedShortArray returns a different ushort value than the
> one in the image?
>
> See the beginning of my image is: (2 bytes each pixel)
>
> *48 248* 48 248 48 248 48 248 48 248 48 248 48 248 48 248
> 48 248 48 248 48 248 48 248 48 248 48 248 48 248 48 248
> 48 248 48 248 48 248 48 248 48 248 48 248 48 248 48 248
> 48 248 48 248 48 248 48 248 48 248 48 248 48 248 48 248
> 48 248 48 248 48 248 48 248 48 248 48 248 48 248 48 248
> 48 248 48 248 48 248
>
> and vtk returns 62512 on every ushort when it should return 63536!
>
> Can you explain why is this or am I missing something?
>
>
> On Fri, Jan 24, 2014 at 10:58 PM, Matias Montroull <matimontg at gmail.com>wrote:
>
>> One more thing, I noticed the data type is "short", so how I get the
>> values in that case?
>>
>>
>> On Fri, Jan 24, 2014 at 10:25 PM, Matias Montroull <matimontg at gmail.com>wrote:
>>
>>> Thanks David,
>>>
>>> So, I've done this and works perfect:
>>>
>>> vtkDICOMImageReader reader =
>>> vtkDICOMImageReader.New();
>>> reader.SetFileName(@"C:\DICOM\img1.dcm");
>>> reader.Update();
>>> vtkImageData vtkimagedata_imagen =
>>> reader.GetOutput();
>>> vtkDataArray array_bytes =
>>> vtkimagedata_imagen.GetPointData().GetScalars();
>>> vtkUnsignedShortArray ushortArray_imagen =
>>> vtkUnsignedShortArray.New();
>>> ushortArray_imagen.DeepCopy(array_bytes);
>>> int[] abc = new int[array_bytes.GetDataSize()];
>>> for (int i = 0; i < array_bytes.GetDataSize(); i++)
>>> {
>>> abc[i] = ushortArray_imagen.GetValue(i);
>>> }
>>>
>>> One more question, is it possible to re-create a Dicom Image from an
>>> ushort Array?
>>>
>>> Thanks again,
>>>
>>> Matias.
>>>
>>>
>>> On Fri, Jan 24, 2014 at 8:24 PM, David Gobbi <david.gobbi at gmail.com>wrote:
>>>
>>>> Hi Matias,
>>>>
>>>> If you have a vtkImageData object, you can get the array though
>>>> VTK's abstract data set interface. Here's an example:
>>>>
>>>> vtkImageData *image = reader->GetOutput();
>>>> vtkDataArray *array = image->GetPointData()->GetScalars();
>>>>
>>>> This will return an array that contains the scalars that are
>>>> associated with each point in the data. For vtkImageData, this
>>>> means the length of the array is the number of pixels in the image,
>>>> so the length will be 262144 (which is 512*512).
>>>>
>>>> If the data is DICOM, the array will probably already be either a
>>>> vtkUnsignedShortArray or a vtkShortArray (signed short). But to
>>>> be sure, you can do a conversion:
>>>>
>>>> vtkUnsignedShortArray *ushortArray = vtkUnsignedShortArray::New();
>>>> ushortArray->DeepCopy(array);
>>>>
>>>> With the ushort array, you can use GetValue(i) to get one of the values.
>>>>
>>>> David
>>>>
>>>>
>>>>
>>>> On Fri, Jan 24, 2014 at 3:46 PM, Matias Montroull <matimontg at gmail.com>
>>>> wrote:
>>>> > Hi,
>>>> >
>>>> > is there a way to obtain the byte array from a Dicom Image?
>>>> >
>>>> > I can display the image but I also need to extract the byte data,
>>>> it's a
>>>> > 512X512 16 bits image, so I need the Ushort array.
>>>> >
>>>> > Thanks!
>>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140204/c172af49/attachment.html>
More information about the vtkusers
mailing list