[ITK] [ITK-users] Proper chaining of filters
Joël Schaerer
joel.schaerer at laposte.net
Thu Oct 2 05:33:06 EDT 2014
Hi all,
I've noticed a couple times that when building a pipeline with ITK, you
need to keep a reference to all filters before the pipeline is updated.
This seems a little counter-intuitive to me, so I would like to better
understand the issue and see if there is a way around it.
As an example, the following code doesn't work:
DilateType::Pointer dilate = DilateType::New();
dilate->SetInput(thresh->GetOutput());
dilate->SetKernel(kernel);
dilate_filters.push_back(dilate);
for (int i=0; i<14; ++i) {
DilateType::Pointer temp = DilateType::New();
temp->SetInput(dilate->GetOutput());
temp->SetKernel(kernel);
dilate = temp;
}
dilate->Update();
Regions don't get propagated properly and I get the following exception
when writing the output:
C++ exception with description
"/home/joel/workspace/ITK/Modules/IO/ImageBase/include/itkImageFileWriter.hxx:290:
itk::ERROR: ImageFileWriter(0x3130460): Largest possible region does not
fully contain requested paste IO regionPaste IO region: ImageIORegion
(0x7fff9bb72cc0)
Dimension: 3
Index: 0 0 0
Size: 0 0 0
Largest possible region: ImageRegion (0x7fff9bb72bc0)
Dimension: 3
Index: [0, 0, 0]
Size: [0, 0, 0]
" thrown in the test body.
My guess is that the filters get destroyed before they get a chance to
be executed. If I explicitely keep references to each filter, it works:
DilateType::Pointer dilate = DilateType::New();
dilate->SetInput(thresh->GetOutput());
dilate->SetKernel(kernel);
// We need to keep a reference to each filter in the pipeline before
it is updated
std::vector<DilateType::Pointer> dilate_filters;
dilate_filters.push_back(dilate);
for (int i=0; i<14; ++i) {
DilateType::Pointer temp = DilateType::New();
temp->SetInput(dilate_filters.back()->GetOutput());
temp->SetKernel(kernel);
dilate = temp;
dilate_filters.push_back(temp);
}
dilate_filters.back()->Update();
My question is, why doesn't a filter keep a reference to the previous
filter in the pipeline? Is there a way around this?
Thanks!
Joël
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list