itkConnectedComponentImageFilter对输入图像大小的限制

    版本信息:Win10(64bit),VS2013(64bit),ITK4.8.2,VTK6.3.0,Qt5.4.2

1 问题描述

    使用VTK实现对3D CT数据进行切片重新提取,然后使用ITK对切片进行二维分析,这是需要使用到itkConnectedComponentImageFilter将灰度图转换为Label Image。当切片的尺寸非常小时(如2x2),会出现错误:

 Debug Assertion Failed!
 
 Program: C:\WINDOWS\SYSTEM32\MSVCP120D.dll
 File: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\vector
 Line: 1201
 
 Expression: vector subscript out of range
 
 For information on how your program can cause an assertion
 failure, see the Visual C++ documentation on asserts.
 
 (Press Retry to debug the application)
   上述提示vector下标越界,而 比较令人疑惑的是,我并没有使用std::vector。继续 使用VS2013进行调试发现错误原因为:

std::vector<std::vector<itk::ConnectedComponentImageFilter<itk::Image<unsigned char,2>,itk::Image<unsigned short,2>,itk::Image<unsigned char,2> >::runLength,std::allocator<itk::ConnectedComponentImageFilter<itk::Image<unsigned char,2>,itk::Image<unsigned short,2>,itk::Image<unsigned char,2> >::runLength> >,std::allocator<std::vector<itk::ConnectedComponentImageFilter<itk::Image<unsigned char,2>,itk::Image<unsigned short,2>,itk::Image<unsigned char,2> >::runLength,std::allocator<itk::ConnectedComponentImageFilter<itk::Image<unsigned char,2>,itk::Image<unsigned short,2>,itk::Image<unsigned char,2> >::runLength> > > >::operator[](unsigned __int64 _Pos) 行 1202	C++

    也即是说itkConnectedComponentImageFilter里面使用了std::vector,并且产生了下标越界。

2 解决方法

    最好的方法就是不要使用itkConnectedComponentImageFilter,而改用其它方法生成Label Image:

//![0] -- UCharImageType
typedef unsigned char UCharPixelType;
typedef itk::Image<UCharPixelType, 2> ImageType;
typedef ImageType itkImageData;
typedef ImageType UCharImageType;
// [0]

//![1] -- UShortImageType
typedef unsigned short UShortPixelType;
typedef itk::Image<UShortPixelType, 2> UShortImageType;
// [1]

typedef itk::BinaryImageToLabelMapFilter<UCharImageType>
    BinaryImageToLabelMapFilterType;

typedef itk::LabelMapToLabelImageFilter
        <BinaryImageToLabelMapFilterType::OutputImageType,
        UShortImageType>
    LabelMapToLabelImageFilterType;
	
BinaryImageToLabelMapFilterType::Pointer binary2Label = 
	BinaryImageToLabelMapFilterType::New();
	
LabelMapToLabelImageFilterType::Pointer  labelMap2LabelImage = 
	LabelMapToLabelImageFilterType::New();
	
binary2Label->SetInput( image ); // image的类型是itkImageData,在上面有定义,此处略去image
binary2Label->Update();			 // 的产生方法

labelMap2LabelImage->SetInput( binary2Label->GetOutput() );
labelMap2LabelImage->UpdateLargestPossibleRegion();
labelMap2LabelImage->Update();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

OneSea

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值