[vtkusers] Byte array from a Dicom Image
Matias Montroull
matimontg at gmail.com
Fri Jan 24 20:25:52 EST 2014
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/20140124/cb060d56/attachment.html>
More information about the vtkusers
mailing list