Hello,
I am working on medical image processing , ITK is a great tool to help me in the implementation. But I have got the exception when the OrImageFilter was using.
Here is my example code segment:
using OrImageFilterType = itk::OrImageFilter<ImageType>;
OrImageFilterType::Pointer orFilter = OrImageFilterType::New();
auto size = image->GetLargestPossibleRegion().GetSize();
auto dim = size.size();
std::vector<ImageType::Pointer> vSlice;
ImageType::Pointer slice;
GetSliceInVolume(image, slice, 0);
vSlice.emplace_back(slice);
orFilter->SetInput(0, slice);
ImageType::Pointer slice1;
GetSliceInVolume(image, slice1, 1);
vSlice.emplace_back(slice1);
orFilter->SetInput(1, slice1);
try{
orFilter->Update();
}
catch (itk::ExceptionObject & e)
{
std::ofstream f("D:\\exception.txt");
f << "Error: " << e << std::endl;
f.close();
return EXIT_FAILURE;
}
And here is the Largestregion and requestedRegion result in the debugging:
vSilce[0]:
thanks for your reply, and sorry for the missing description about exception. The exception I have got is “Requested region is (at least partially) outside the largest possible region”. I thought it was caused by the inconformity between the requested region and largestpossibleregion in slice1. and then I add function slice->SetRequestedRegionToLargestPossibleRegion(); to make sure the requestedRegion and largestPossibleRegion is same, but the same exception was still thrown after this. At last, I add this code segment to make sure all the regions in the different slices are same.
after this, it can work. Does it means the OrImageFilter can only accept input images with the same region index and size?
In my task, I need to do the OR operation between all the image slices, I found the OrImageFilter can only accept two images one time.
BTW, what is the meaning of the different region in image object? Thanks a lot.
I guess I did not pay attention to the topic title
The deeper you dive into ITK, and the closer you get to internals, more weirdness you will encounter. Setting the RequestedRegion, might be required, or that need might stem from how GetSliceInVolume is implemented. If you found a way which works, keep it.
To learn more about different image regions, take a look at the ITK software guide.
OrFilter can only operate on two images at a time, and the must have same index, size, origin, spacing and direction. If you want to make a slice-wise OR of the entire 3D volume, you can use a temporary image and for loop. Pseudocode:
This guide is great for me. GetSliceInVolume is implemented by ExtractImageFilter. Is there some more reasonable solution before OrImageFilter except this one(setting all the region to same)?
Thanks a lot.