[vtkusers] Pixel Values

Sean McBride sean at rogue-research.com
Thu Jun 16 10:21:07 EDT 2005


On 2005-06-14 21:17, brunos at lncc.br said:

>I´m a new VTK user and I want to access image pixels. For this purpose I
>´m using
>the code below:
>
>	vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
>	reader->SetFileName("c:/temp/DICOM/DICOM55.dcm");
>	reader->Update();
>
>	short *Pixels;
>	int i;
>
>	Pixels = (short *) reader->GetOutput()->GetScalarPointer();
>
>	FILE *fp = fopen("c:/temp/pixels.txt","w");
>
>	for(i=0; i < 512*512; i++)
>	{
>		fprintf(fp, "%d ", *Pixels++);
>	}
>
>	fclose(fp);
>
>	return 0;
>
>However, the files generated by this code, contain values above 255 and below
>0. For example -2048, 543, 1020 -1028.
>Is it correct?
>Is there some different standard to pixels representation in VTK ?
>Or is there other way to access pixels values ?

I'm also new to vtk, so don't trust me. :)

But why do you assume values will be between 0 and 255?  Your 'Pixels'
is a short* not a char*, so larger values are not surprising.  Maybe it
should be 'unsigned'?  Maybe you should call vtkImageData's GetScalarType
() and switch on that?

hth,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtkusers mailing list