#include
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingContextOpenGL2)
VTK_MODULE_INIT(vtkRenderingFreeType)
#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 "itkImageFileWriter.h"
#include "itkCastImageFilter.h"
#include "itkGDCMImageIOFactory.h"
#include
#include
using namespace std;
int main(int argc, char* argv[])
{
typedef itk::Image ImageType;
typedef itk::Image UnsignedCharImageType;
typedef itk::ImageFileReader ReaderType;
typedef itk::ImageToVTKImageFilter ConnectorType;
std::string DCM = ".DCM";
itk::GDCMImageIOFactory::RegisterOneFactory();
for (int num = 1; numSetFileName(inputFilename);
//reader->SetImageIO( );
//itk::GDCMImageIOFactory::RegisterOneFactory();
reader->Update();
ImageType::SizeType inputSize = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
std::cout << "Original size: " <GetOutput()->GetLargestPossibleRegion().GetSize() <GetOutput()->GetSpacing()[0];
outputSpacing[1] = reader->GetOutput()->GetSpacing()[1];
typedef itk::BinaryThresholdImageFilter FilterType;
FilterType::Pointer Thresholdfilter = FilterType::New();
Thresholdfilter->SetInput(reader->GetOutput());
Thresholdfilter->SetLowerThreshold(100);
Thresholdfilter->SetUpperThreshold(180);
//默认设置 SetInsideValue 255 SetOutsideValue 0
Thresholdfilter->Update();
/* typedef itk::BinaryBallStructuringElement
StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(8);
structuringElement.CreateStructuringElement();
typedef itk::BinaryMorphologicalOpeningImageFilter
BinaryMorphologicalOpeningImageFilterType;
BinaryMorphologicalOpeningImageFilterType::Pointer openingFilter
= BinaryMorphologicalOpeningImageFilterType::New();
openingFilter->SetInput(Thresholdfilter->GetOutput());
openingFilter->SetKernel(structuringElement);
openingFilter->Update();
*/
typedef itk::CastImageFilter CastFilterType;
CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput(Thresholdfilter->GetOutput());
typedef itk::ImageFileWriter WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(castFilter->GetOutput());
writer->Update();
}
return 0;
}
今天试了下,如果还转换成unsigned short数据,相当于没转,只是做了下滤波,新数据就少了3Kb,不知道为什么,ITK不是专门处理医学图像的吗,为何他的Demo里多是png图像,真搞不懂
作者:peanut_wu