《itk实用demo》-DCM提取二值图像

区域生长

#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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值