[vtkusers] Read Particular pixel value

Kannan U V kannanuv at cshl.edu
Wed Nov 6 15:27:26 EST 2013


Thanks David for the pointer, it worked. I am setting the imageData
variable from a metaImageReader so AllocateScalar wasn't necessary.

I thought I should mention this, even though my meta image was
unsigned_short, the reader output was float. Is the functionality of every
image reader?


On Tue, Nov 5, 2013 at 2:35 PM, David Doria <daviddoria at gmail.com> wrote:

> On Tue, Nov 5, 2013 at 2:18 PM, Kannan U V <kannanuv at cshl.edu> wrote:
> > Hi,
> > I am trying to find the value of a label at particular point in the
> image.
> > The pickedPoint gives me the x,y,z co-ordinate where I should pick the
> > value. How do I find the image value at that voxel? Since it is a label
> > image I want to use nearest neighbor interpolation. Can anyone give me
> > pointers of how to get the label value?
> >
> >
> > vtkRenderWindowInteractor* iren =
> > vtkRenderWindowInteractor::SafeDownCast(obj);
> >
> > iren->SetPicker(picker);
> >
> > // get event position
> > int event_pos[2];
> > iren->GetEventPosition(event_pos);
> >
> > // update label
> > QString str;
> >
> > iren->GetPicker()->Pick(iren->GetEventPosition()[0],
> > iren->GetEventPosition()[1], 0,
> > iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
> > double pickedPoint[3];
> > iren->GetPicker()->GetPickPosition(pickedPoint);
> >
> > vtkSmartPointer<vtkImageCast> imageCast =
> > vtkSmartPointer<vtkImageCast>::New();
> > vtkSmartPointer<vtkImageData> atlasLabelImageData =
> > vtkSmartPointer<vtkImageData>::New();
> >
> > imageCast->SetInput(atlasLabelsReader->GetOutput());
> > imageCast->SetOutputScalarTypeToUnsignedShort();
> > imageCast->Update();
> > atlasLabelImageData = imageCast->GetOutput();
> > unsigned long labelCellID = (unsigned short)
> > atlasLabelImageData->FindPoint(pickedPoint);
> >
> > str.sprintf("(x, y, z) = (%3.2f, %3.2f, %3.2f), Label Value = %f",
> > pickedPoint[0], pickedPoint[1], pickedPoint[2], labelCellID);
> >
> > --
> > Thanks,
> > Kannan
>
>
> This kind of question is appropriate for the vtk-users list - the
> developers list is reserved for questions about the internals of VTK.
>
> I think you're looking for:
>
> double* pixel = static_cast<double*>(imageData->GetScalarPointer(x,y,z));
>
> where that type (double) should match the type of your image (e.g. in
> this case the image should have been allocated with
> imageData->AllocateScalars(VTK_DOUBLE,1);)
>
> There is a example that demonstrates this type of access here:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageData/IterateImageData
>
> David
>



-- 
Thanks,
Kannan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131106/7946e2a5/attachment.htm>


More information about the vtkusers mailing list