[vtkusers] Read Particular pixel value
David Doria
daviddoria at gmail.com
Tue Nov 5 14:35:34 EST 2013
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
More information about the vtkusers
mailing list