最近要做一个关于对医学影像进行自动分割的功能,在对几种itk自带的几种区域增长的算法进行测试时,发现其最终输出的结果都是二值图像,然而我想要的是对提取的ROI区域保留其原始的灰度值,显然其原始的算法是不满足我的要求的。
经过我对itkConnectedThresholdImageFilter.hxx源码的研究,发现,其结果的二值图像的产生是在函数GenerateData()函数里实现的;于是,我们只要对GenerateData()函数进行细节的一点点的修改即可到达我们想要的效果了。
为了不修改ITK自身的源码,我通过对itkConnectedThresholdImageFilter了进行了扩展,具体的代码如下:
MyConnectedThresholdImageFilter.h文件
#ifndef MyConnectedThresholdImageFilter_h
#define MyConnectedThresholdImageFilter_h
#include "itkConnectedThresholdImageFilter.h"
#include "itkSimpleDataObjectDecorator.h"
namespace itk
{
template <typename TInputImage, typename TOutputImage>
class ITK_TEMPLATE_EXPORT MyConnectedThresholdImageFilter : public ConnectedThresholdImageFilter<TInputImage, TOutputImage>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(MyConnectedThresholdImageFilter);
/** Standard class type aliases. */
using Self = MyConnectedThresholdImageFilter;
using Superclass = ConnectedThresholdImageFilter<TInputImage, TOutputImage>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self&g