C++ Itk:ImageRegionIterator GetIndex()调用使程序出错
我正在迭代Ikt::Image的一个区域。根据程序的输入,此图像可能会有所不同。总结课程的主要部分:C++ Itk:ImageRegionIterator GetIndex()调用使程序出错,c++,itk,C++,Itk,我正在迭代Ikt::Image的一个区域。根据程序的输入,此图像可能会有所不同。总结课程的主要部分: //inputMask is an input and contains a label image typedef typename itk::ImageRegionIterator<TInputImage> InputIteratorType; std::auto_ptr<InputIteratorType> pIit; if(someBool) { //
//inputMask is an input and contains a label image
typedef typename itk::ImageRegionIterator<TInputImage> InputIteratorType;
std::auto_ptr<InputIteratorType> pIit;
if(someBool)
{
// here I remove some labeled areas, based on some characteristics
// ...
// relabeledMask = result of the evaluations
InputIteratorType iit(relabeledMask, relabeledMask->GetLargestPossibleRegion());
pIit.reset(&iit);
}
else
{
InputIteratorType iit(inputMask, inputMask->GetLargestPossibleRegion());
pIit.reset(&iit);
}
for (pIit->GoToBegin(); !pIit->IsAtEnd(); ++(*pIit))
{
if (pIit->Value() > 0)
{
typename TInputMask::IndexType seed = pIit->GetIndex();
// remaining part of the program
// ...
//
}
}
//inputMask是一个输入,包含一个标签图像
typedef typename itk::ImageRegionIterator InputIteratorType;
标准::自动ptr pIit;
if(someBool)
{
//在这里,我根据一些特征删除了一些标记区域
// ...
//RelabledMask=评估结果
输入utiteratorType iit(RelabledTask,RelabledTask->GetLargestPossibleRegion());
pIit.重置(&iit);
}
其他的
{
InputIteratorType iit(inputMask,inputMask->GetLargestPossibleRegion());
pIit.重置(&iit);
}
对于(pIit->GoToBegin();!pIit->isattend();++(*pIit))
{
如果(pIit->Value()>0)
{
typename TInputMask::IndexType seed=pIit->GetIndex();
//计划的剩余部分
// ...
//
}
}
现在。。。只有当someBool
为false时,的最后一个才有效。如果为真,程序将在第typename TInputMask::IndexType seed=pIit->GetIndex()行崩溃代码>带有分段故障(堆芯转储)
此外,如果我把这个for
放在if(someBool)
中(就在pIit.reset(&iit);
之后),程序不会崩溃
最后一点,如果我将relabledimage
保存为一个漂亮的文件,我可以毫无问题地看到该卷的每一张幻灯片
有什么想法吗?itk::ImageRegionIterator
等,用弱指针指向图像
因此,您的重新标记图像
很可能被破坏。另一种方法是有条件地引用图像:
TInputImage::Pointer imageToIterate;
if ( /* something */ )
{
// do stuff
theFilter->Update();
imageToIterate = theFilter->GetOutput();
}else
{
// do other stuff
}
typedef typename itk::ImageRegionIterator<TInputImage> InputIteratorType;
InputIteratorType iit(imageToIterate,imageToIterate->GetLargestPossibleRegion());
// iterate!
TInputImage::指针ImageToItem;
如果(/*某物*/)
{
//做事
过滤器->更新();
imageToIterate=theFilter->GetOutput();
}否则
{
//做其他事情
}
typedef typename itk::ImageRegionIterator InputIteratorType;
输入utiteratorType iit(ImageToItem,ImageToItem->GetLargestPossibleRegion());
//迭代!
谢谢,我认为这与图像被破坏有关,但我没有意识到弱指针问题。实际上,我通过添加一个函数来解决这个问题,该函数包含迭代器的创建、最后一个for
以及代码的其余部分(未在此处发布)。我将if
(重新标记)或else
(原始)中的相应标签图像传递给此函数。