面向对象的itk封装类

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/rabbitbride/article/details/83116482

itktestClass - 本人第一个itk封装类 - 注意数据格式,还是2015年,在此分享给新手学习。不经意间,快4年了,times fly。
功能简单,用itk实现了一个区域生长,然后和vtk互相转换。
抛砖引玉 O(∩_∩)O

1.头文件h

//
// Author: winston600 @xxxx 2015.01.08
// Module: xxxx分割算法
//

#ifndef itktestClass_H
#define itktestClass_H

#include "itkImage.h"
#include "vtkImageData.h"


class itktestClass
{
public:
 itktestClass();
 ~itktestClass();

 void SetInput(vtkImageData *inputData)
 {
  xxxxData->ShallowCopy(inputData);
 }
 void myitkFunction();

 vtkImageData*  GetOutput() { return xxxxData1 ;}
protected:
 typedef itk::Image<short,2> ImageType;
 typedef itk::Image<unsigned char, 2>  UnsignedCharImageType;
private:
 vtkImageData *xxxxData;
 vtkImageData *xxxxData1;
};

#endif

2.源文件cpp

//
// Author: winston600 @xxxx 2015.01.08
// Module: xxxx分割算法
//

#include "StdAfx.h"
#include "itktestClass.h"

#include "itkConnectedThresholdImageFilter.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include "itkVTKImageToImageFilter.h"

itktestClass::itktestClass()
{
 xxxxData = vtkImageData::New();
 xxxxData1 = vtkImageData::New();
}
itktestClass::~itktestClass()
{
}

void itktestClass::myitkFunction()
{
 typedef itk::VTKImageToImageFilter<ImageType> VTK2ITKFilter;
 VTK2ITKFilter::Pointer vtk2itk = VTK2ITKFilter::New();
 vtk2itk->SetInput(xxxxData);
 vtk2itk->Update();

 typedef itk::ConnectedThresholdImageFilter<ImageType, ImageType> ConnectedFilterType0;
 ConnectedFilterType0::Pointer connectedThreshold0 = ConnectedFilterType0::New ();
 connectedThreshold0->SetInput( vtk2itk->GetOutput() );
 ImageType::IndexType  seed0;
 seed0[0] = 75;
 seed0[1] = 142;
 //seed0[2] = 21;
 connectedThreshold0->AddSeed(seed0);
 connectedThreshold0->SetLower(  800 );
 connectedThreshold0->SetUpper( 3000 );
 connectedThreshold0->Update();

 typedef itk::BinaryThresholdImageFilter<ImageType, ImageType>  FilterType;
 FilterType::Pointer Thresholdfilter = FilterType::New();
 Thresholdfilter->SetInput( connectedThreshold0->GetOutput() );
 Thresholdfilter->SetLowerThreshold(1);
 //Thresholdfilter->SetUpperThreshold(3000);
 Thresholdfilter->SetInsideValue(255);
 Thresholdfilter->SetOutsideValue(0);
 //默认设置 SetInsideValue 255 SetOutsideValue 0
 Thresholdfilter->Update();

 typedef itk::CastImageFilter<ImageType, UnsignedCharImageType > CastFilterType;
 CastFilterType::Pointer castFilter = CastFilterType::New();
 castFilter->SetInput(Thresholdfilter->GetOutput());

 typedef itk::ImageToVTKImageFilter<ImageType> itkVtkConverter;
 itkVtkConverter::Pointer conv=itkVtkConverter::New();
 conv->SetInput(Thresholdfilter->GetOutput());
 conv->Update();/////////////
 
 xxxxData1->DeepCopy(conv->GetOutput());/////

}

在这里插入图片描述

展开阅读全文

没有更多推荐了,返回首页