itk中的花式数据切割(五)

今天继续研究数据切割,也是对之前四篇切割内容的补充,内容不多,step by step。

itk中有一个类叫做itkCropImageFilter,是itkExtractImageFilter的派生方法。


先上代码,看一下基本用法:

ImageType::SizeType   extractSize = {{8, 12}};  
extractSize[0] = 1; 
extractSize[1] = 1;

typedef itk::CropImageFilter <ImageType, ImageType> CropImageFilterType;
CropImageFilterType::Pointer cropFilter  = CropImageFilterType::New();
cropFilter->SetInput(input_data);
cropFilter->SetBoundaryCropSize(extractSize); //和下面两句重复
//cropFilter->SetUpperBoundaryCropSize(extractSize);
//cropFilter->SetLowerBoundaryCropSize(extractSize);
cropFilter->UpdateLargestPossibleRegion();
cropFilter->Update();

接下来咱们一起看源码是怎么写的,这个类超简单,就一个函数,但我看了还是诧异,+_+:

template <class TInputImage, class TOutputImage>// itk的模版
void
CropImageFilter<TInputImage, TOutputImage>
::GenerateOutputInformation()//itk的数据生成都用的这个函数名
{
  const TInputImage * inputPtr = this->GetInput();
  if( !inputPtr )//防爆安全代码
    {
    return;
    }
  
  // Compute the new region size.
  OutputImageRegionType croppedRegion;
  SizeType   sz;
  OutputImageIndexType   idx;

  InputImageSizeType input_sz =
    inputPtr->GetLargestPossibleRegion().GetSize();
  InputImageIndexType input_idx =
    inputPtr->GetLargestPossibleRegion().GetIndex();

  idx = input_idx + m_LowerBoundaryCropSize; 
  sz  = input_sz  - (m_UpperBoundaryCropSize + m_LowerBoundaryCropSize); 

  croppedRegion.SetSize(sz);
  croppedRegion.SetIndex(idx);

  // Set extraction region in the superclass.
  this->SetExtractionRegion(croppedRegion);//父类的函数生效

  // 
  Superclass::GenerateOutputInformation();
}

看下面两行!@_@,我有点晕了,亲测后,原来是按照给定的size对原始图像做对称切割!
idx = input_idx + m_LowerBoundaryCropSize; 
sz  = input_sz  - (m_UpperBoundaryCropSize + m_LowerBoundaryCropSize); 
测试结果:(貌似这是第一个与文章内容相关的图)


这个方法,挺好用,但怎么用呢?貌似也没什么情况用得到啊~

最近有一些新的idea,想脚踏实地亲自做一些脚踏实地的事情,做一些有用的事情。现在的状态是不上不下,简直就是一个“卡”啊!这么在半空中是很危险的,想落地。
别急,别急,一件一件来~

---“勤学似春起之苗,不见其增,日有所长。”  与大家共勉。
参考文献:
1. https://itk.org/Wiki/ITK/Examples/ImageProcessing/CropImageFilter

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值