[vtkusers] Picking a pixel from an image (works, but ...)

John Smith af3113 at yahoo.com
Sun Jan 3 01:03:39 EST 2010


Hi Dean,

Sorry for the late answer! I have tried your method to pick a pixel from an image and it works like magic. I even have noticed that you have submitted an example to VTK public wiki; great work!!!

Thanks a lot.

Cheers,

J

--- On Wed, 12/16/09, Dean Inglis <dean.inglis at camris.ca> wrote:

> From: Dean Inglis <dean.inglis at camris.ca>
> Subject: Re: [vtkusers] Picking a pixel from an image (works, but ...)
> To: "vtkusers archive" <vtkusers at vtk.org>
> Date: Wednesday, December 16, 2009, 8:30 PM
> 
> Hi J,
> 
> here is what I would try:
> make your picker a vtkPropPicker:
> 
>  this->Picker = vtkPropPicker::New();
>  this->Picker->PickFromListOn();
> 
> then give it something to pick:
> 
>  this->Picker->AddPickList(
> imageViewer->GetImageActor() );
> 
> watch for pick events or mouse move event of an interactor
> etc.
> 
>  double q[3];
>  this->Picker->GetPickPosition( q );
> 
> now the tricky bits where we interpolate the position to
> get an image value:
> 
>  vtkPointData* pd = imageViewer->GetImageActor()
> ->GetInput()->GetPointData();
>  if( !pd ) return;
> 
>  vtkPointData* outPD = vtkPointData::New();
>  outPD->InterpolateAllocate( pd, 1, 1 );
> 
>  // Use tolerance as a function of size of source data
>  //
>  double tol2 = imageViewer->GetImageActor()
> ->GetInput()->GetLength();
>  tol2 = tol2 ? tol2*tol2 / 1000.0 : 0.001;
> 
>  // Find the cell that contains q and get it
>  //
>  int subId;
>  double pcoords[3], weights[8];
>  vtkCell* cell = imageViewer->GetImageActor()
> ->GetInput()->FindAndGetCell(
>    q, NULL, -1, tol2, subId, pcoords,
> weights );
>  if( cell )
>  {
>    int components;
>    double* tuple;
> 
>    // Interpolate the point data
>    //
>    outPD->InterpolatePoint( pd, 0,
> cell->PointIds, weights );
>    components =
> outPD->GetScalars()->GetNumberOfComponents();
>    tuple =
> outPD->GetScalars()->GetTuple( 0 );
> 
>  here is where you would display the contents of your
> tuple...
> 
> vtkStdString s = "output: ";
>  for(int i=0;i<components;++i)
> {
> s+=vtkVariant(tuple[i]).ToString();
> s+=",";
> }
> 
>  }
> 
>  outPD->Delete();
> 
> HTH,
> Dean
> 
> Dear all,
> 
> I have a little problem picking a pixel from a
> vtkImageViewer2. I use vtkPointPicker for that. Here's the
> procedure I use:
> 
> 1.Get mouse location in scene space:
> double point[3];
> picker->GetMapperPosition(point);
> 2.Get correct mapped z-location:
> double spacing[3];
> imageViewer->GetInput()->GetSpacing(spacing);
> point[2] = imageViewer->GetSlice() * spacing[2];
> 3.Get the actual volume index of the mouse over pixel;
> int index =
> imageViewer->GetInput()->FindPoint(point);
> double* scalarPointer =
> (double*)imageViewer->GetInput()->GetScalarPointer();
> double intensity = scalarPointer[index];
> 
> 4.Printing the picked pixel coordinates and the pixel
> intensity:
> cerr << "(" << point[0] << ", " <<
> point[1] << ", " << point[2] << "):
> "  << intensity;
> 
> The problem I have is that I always get wrong values
> comparing to other programs. Maybe I miss something out.
> 
> Thank you in advance.
> 
> Regards,
> 
> J.
> 
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 


      



More information about the vtkusers mailing list