为什么把一个序列的DICOM数据有short型转化成 unsigned char型以后,重建失败,不做类型转换也是少了3Kb,请教大神?

#include <vtkAutoInit.h> 
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 <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	typedef itk::Image<unsigned char, 2> ImageType;
	typedef itk::Image<unsigned char, 2>  UnsignedCharImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
	std::string DCM = ".DCM";
	 
	itk::GDCMImageIOFactory::RegisterOneFactory();
	for (int num = 1; num<118; num++)
	{
		 
		std::string  inputFilename = "E:\\imgdata\\2013-06-04\\1.2.840.113619.2.55.3.2831155457.416.1370299545.455";
		std::string  outputFilename = "D:\\IM\\1.2.840.113619.2.55.3.2831155457.416.1370299545.455";
		char t[256];
		string s;
		sprintf_s(t, ".%d", num);
		s = t;
		inputFilename = inputFilename + s + DCM;
		outputFilename = outputFilename + s + DCM;
		struct stat buffer;
		if (stat(inputFilename.c_str(), &buffer) != 0)
			continue;

		ReaderType::Pointer reader = ReaderType::New();
		ConnectorType::Pointer connector = ConnectorType::New();
		reader->SetFileName(inputFilename);
		//reader->SetImageIO( );
		//itk::GDCMImageIOFactory::RegisterOneFactory();
		 
		reader->Update();
		

		ImageType::SizeType inputSize = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
		std::cout << "Original size: " << reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;
		// Resize
		ImageType::SizeType outputSize;
		outputSize[0] = inputSize[0];
		outputSize[1] = inputSize[1];
		ImageType::SpacingType outputSpacing;
		outputSpacing[0] = reader->GetOutput()->GetSpacing()[0];
		outputSpacing[1] = reader->GetOutput()->GetSpacing()[1];
 
		typedef itk::BinaryThresholdImageFilter<ImageType, ImageType>  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<ImageType::PixelType, ImageType::ImageDimension>
			StructuringElementType;
		StructuringElementType structuringElement;
		structuringElement.SetRadius(8);
		structuringElement.CreateStructuringElement();
		typedef itk::BinaryMorphologicalOpeningImageFilter <ImageType, ImageType, StructuringElementType>
			BinaryMorphologicalOpeningImageFilterType;
		BinaryMorphologicalOpeningImageFilterType::Pointer openingFilter
			= BinaryMorphologicalOpeningImageFilterType::New();
		openingFilter->SetInput(Thresholdfilter->GetOutput());
		openingFilter->SetKernel(structuringElement);
		openingFilter->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;
}

今天试了下,如果还转换成unsigned short数据,相当于没转,只是做了下滤波,新数据就少了3Kb,不知道为什么,ITK不是专门处理医学图像的吗,为何他的Demo里多是png图像,真搞不懂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值