赞
踩
BlackTopHat:闭运算结果-原图像
使用方法:
- typedef itk::BinaryBallStructuringElement<PixelType, ImageDimension > SRType;
- SRType kernel;
- kernel.SetRadius( 22 );
- kernel.CreateStructuringElement();
-
- //typedef itk::WhiteTopHatImageFilter<ImageType,ImageType,SRType > TopHatFilterType;
- typedef itk::BlackTopHatImageFilter<ImageType,ImageType,SRType > TopHatFilterType;
- TopHatFilterType::Pointer topHatFilter = TopHatFilterType::New();
- topHatFilter->SetInput( intput_data );
- topHatFilter->SetSafeBorder( false);
- topHatFilter->SetKernel( kernel );
- topHatFilter->Update();
- template <class TInputImage, class TOutputImage, class TKernel>
- void
- WhiteTopHatImageFilter<TInputImage, TOutputImage, TKernel>
- ::GenerateData()
- {
- // Create a process accumulator for tracking the progress of this minipipeline 创建了一个能跟踪算法步骤的管道?
- ProgressAccumulator::Pointer progress = ProgressAccumulator::New();
- progress->SetMiniPipelineFilter(this);
-
- // Allocate the output 初始化输出数据
- this->AllocateOutputs();
-
- // Delegate to an opening filter.对灰度图像做开运算
- typename GrayscaleMorphologicalOpeningImageFilter<TInputImage, TInputImage, TKernel>::Pointer
- open = GrayscaleMorphologicalOpeningImageFilter<TInputImage, TInputImage, TKernel>::New();
-
- open->SetInput( this->GetInput() );//输入图像
- open->SetKernel( this->GetKernel() );//输入模版
- open->SetSafeBorder( m_SafeBorder );//设置安全边界
-
- // Need to subtract the opened image from the input 两图像做相减
- typename SubtractImageFilter<TInputImage, TInputImage, TOutputImage>::Pointer
- subtract=SubtractImageFilter<TInputImage,TInputImage,TOutputImage>::New();
-
- subtract->SetInput1( this->GetInput() );//输入原图像
- subtract->SetInput2( open->GetOutput() );//输入开运算结果
-
- // graft our output to the subtract filter to force the proper regions
- // to be generated 按照输出数据的大小设置减法滤波器的结果
- subtract->GraftOutput( this->GetOutput() );
-
- // run the algorithm
- progress->RegisterInternalFilter(open,.9f);
- progress->RegisterInternalFilter(subtract,.1f);
-
- subtract->Update();
-
- // graft the output of the subtract filter back onto this filter's
- // output. this is needed to get the appropriate regions passed
- // back.刷新输出数据
- this->GraftOutput( subtract->GetOutput() );
-
- }
这里有个需要注意的点,在TopHat中,需要预设模版,模版的尺寸会影响滤波的结果。模版应该比目标大一点,刚好能覆盖过目标的细节。对应代码中的itkBinaryBallStructuringElement设置。实际上,这也是TopHat算法的优势,可以灵活的设置模版来适应不同的情况。
感谢网友分享,下面的解释很明朗,贴一下:
图像f 的顶帽变换h定义为图像f与图像f的开运算之差, 可表示为: h = f -(f*s)
有一次去莫干山玩,路上居然遇到一只狐狸,这可太稀奇了。心血来潮,我远远地冲它大喝一声:“孽畜!还不快快现出原形?!”狐狸愣了一下,居然开口说话了:“这本来就是原形啊!”“妈呀有妖怪!”我大叫一声,撒丫子就跑,狐狸嗷地一声跟在我后面跑,边跑边叫:“哪儿,哪儿有妖怪啊?别丢下我!吓死我了!”
参考文献:
1.http://blog.csdn.net/stscsdn/article/details/52523002
2.http://blog.csdn.net/whuhan2013/article/details/53958394
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。