由于ITK不支持可视化,处理完后必须先写入文件才能查看结果,我们可以结合VTK将处理结果可视化,快速查看图像处理结果。
这里举一个简单的例子,读取dicom图像,并rescale到0~255,然后VTK显示结果。
有两种方式显示结果:
viewer.AddImage(image.GetPointer());
viewer.AddImage(rescaleFilter->GetOutput());
下面给出完整代码:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRescaleIntensityImageFilter.h"
#include "QuickView.h"
typedef itk::Image<unsigned char, 2> ImageType;
int main(int argc, char *argv[])
{
ImageType::Pointer image;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("C:/input/lung.dcm");
image = reader->GetOutput();
typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > RescaleFilterType;
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(image);
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->Update();
QuickView viewer;
viewer.AddImage(image.GetPointer());
viewer.AddImage(rescaleFilter->GetOutput());
viewer.Visualize();
return EXIT_SUCCESS;
}
显示结果