Hey all,
I’m trying to use ITKs LabelImageToLabelMapFilter in one of my plugins. I have
the following code:
void SplitComponentsView::loadImageButtonPressed() {
typedef itk::Image<unsigned char, 3> ImageType;
mitk::DataNode::Pointer imageNode =
m_Controls.imageSelector->GetSelectedNode();
if (imageNode) {
MITK_INFO(“ch.zhaw.splitcomponents") << “processing input”;
// left out the exception handling for input to shorten this example
mitk::Image::Pointer mitkImage =
dynamic_cast<mitk::Image*>(imageNode->GetData());
ImageType::Pointer itkImage = ImageType::New();
mitk::CastToItkImage(mitkImage, itkImage);
MITK_INFO(“ch.zhaw.splitcomponents") << “create label image”;
typedef itk::ConnectedComponentImageFilter <ImageType, ImageType >
ConnectedComponentImageFilterType;
ConnectedComponentImageFilterType::Pointer
connectedComponentImageFilter = ConnectedComponentImageFilterType::New ();
connectedComponentImageFilter->SetInput(itkImage);
connectedComponentImageFilter->UpdateLargestPossibleRegion();
MITK_INFO(“ch.zhaw.splitcomponents") << “create label map”;
typedef itk::LabelImageToLabelMapFilter <ImageType>
LabelImageToLabelMapFilterType;
LabelImageToLabelMapFilterType::Pointer labelImageToLabelMapFilter =
LabelImageToLabelMapFilterType::New ();
labelImageToLabelMapFilter->SetInput(connectedComponentImageFilter->GetOutput());
labelImageToLabelMapFilter->Update();
MITK_INFO << "There are " <<
labelImageToLabelMapFilter->GetOutput()->GetNumberOfLabelObjects() << "
objects.”;
}
}
Executing it will crash the workbench with the following error:
[2.693] [ch.zhaw.splitcomponents] processing input
[2.693] [ch.zhaw.splitcomponents] create label image
[3.439] [ch.zhaw.splitcomponents] create label map
Workbench(66541,0x117351000) malloc: *** error for object 0x7f91422adfc0:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
/Users/fitz/Library/Caches/clion10/cmake/generated/38b56cd0/38b56cd0/Release0/Workbench-Project:
line 2: 66541 Abort trap: 6
./Workbench-Project-build/Workbench.app/Contents/MacOS/Workbench
Process finished with exit code 134
The connectedComponentImageFilter output is valid and it works when i leave out
the LabelImageToLabelMapFilter part. The same ITK code works standalone (with
no MITK involved) and even when i abstract the ITK part into a separate class
and let it execute via QThread. I understand what the error message is saying,
but i do not understand what could cause this? To my understanding, the above
code should not have any memory problems at all (assuming the ITK filters have
no bugs). The allocations should be:
1) mitkImage, owned and managed by the data node / storage.
2) itkImage, ITK copy of mitkImage. Local scope, will be deconstructed at end
of scope
At the end of the block, all references to itkImage will go out of scope and
thus the image will be deconstructed. Imo everything is ok.
Any ideas? Are there any known issues with MITK and this specific ITK filter?
cheers,
Thomas
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users