VTK中图像像素位置的提取

当使用VTK对图像进行显示,图像像素点的提取是其中一个重要的应用,包括对像素位置的判断,以及对像素值的读取。

对像素点提取的思路包括三个步骤:

获取renderer的指针,然后使用picker类来获得点击的点。

			int *pos = this->GetInteractor()->GetEventPosition();
			this->picker->Pick( pos[0], pos[1], 0.0, imageViewer->GetRenderer() );
			double selectionPos[3];
			this->picker->GetPickPosition(selectionPos);
在求解pick位置的过程中,需要对其进行操作,以得到具体的位置。
			// Fixes some numerical problems with the picking
			double *bounds = this->imageViewer->GetImageActor()->GetDisplayBounds();
			//std::cout << bounds[4] << std::endl;
			int axis = this->imageViewer->GetSliceOrientation();
			selectionPos[axis] = bounds[2*axis];
对得到的位置进行插值,提取对应的像素值

      vtkPointData* pd = image->GetPointData();
      if( !pd )
        {
        return;
        }
 
      this->PointData->InterpolateAllocate( pd, 1, 1 );
 
      // Use tolerance as a function of size of source data
      double tol2 = image->GetLength();
      tol2 = tol2 ? tol2*tol2 / 1000.0 : 0.001;
 
      // Find the cell that contains pos
      int subId;
      double pcoords[3], weights[8];
      vtkCell* cell = image->FindAndGetCell(
          pos, NULL, -1, tol2, subId, pcoords, weights );
      if( cell )
        {
        // Interpolate the point data
        this->PointData->InterpolatePoint( pd, 0, cell->PointIds, weights );
        int components =
          this->PointData->GetScalars()->GetNumberOfComponents();
        double* tuple = this->PointData->GetScalars()->GetTuple( 0 );

参考文献:




  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值