版权声明:本文为博主原创文章,转载请注明出处,谢谢 https://blog.csdn.net/rabbitbride/article/details/82422083
区域生长
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageViewer.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "itkResampleImageFilter.h"//采样
#include "itkBinaryThresholdImageFilter.h"//二值化
#include "itkThresholdImageFilter.h"//阈值分割
#include "itkBinaryBallStructuringElement.h"
#include "itkBinaryMorphologicalOpeningImageFilter.h"//开运算
#include "itkMultiplyImageFilter.h"//乘法
#include "itkAndImageFilter.h"//与
#include "itkImageFileWriter.h"
#include "itkCastImageFilter.h"
#include <iostream>
#include <string>
#include "itkConnectedComponentImageFilter.h"//连通域
#include "itkLabelToRGBImageFilter.h"//彩色
#include "itkConnectedThresholdImageFilter.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
typedef itk::Image<unsigned short,2> ImageType;
typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
std::string bmp = ".bmp";
std::string dcm = ".dcm";
double factor = 2.0;
for (int num= 0;num<34;num++)
{
std::string inputFilename = "D:\\se6\\ct9\\image";
std::string outputFilename = "D:\\se6\\bmp\\image";
char t[256];
string s;
sprintf(t, "%03d", num);
s = t;
inputFilename = inputFilename + s + dcm;
outputFilename = outputFilename + s + bmp;
ReaderType::Pointer reader= ReaderType::New();
ConnectorType::Pointer connector= ConnectorType::New();
reader->SetFileName(inputFilename);
reader->Update();
typedef itk::ConnectedThresholdImageFilter<ImageType, ImageType> ConnectedFilterType0;
ConnectedFilterType0::Pointer connectedThreshold0 = ConnectedFilterType0::New ();
connectedThreshold0->SetInput( reader->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::ImageFileWriter< UnsignedCharImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(castFilter->GetOutput());
writer->Update();
}
return 0;
}