The exception(Requested region is (at least partially) outside the largest possible region) in orImageFilter.

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);
		orFilter->SetInput(0, slice);

		ImageType::Pointer slice1;
		GetSliceInVolume(image, slice1, 1);
		orFilter->SetInput(1, slice1);

		catch (itk::ExceptionObject & e)
			std::ofstream  f("D:\\exception.txt");
			f << "Error: " << e << std::endl;
			return EXIT_FAILURE;

And here is the Largestregion and requestedRegion result in the debugging:



  1. what is the reason of the exception, and how to fix it?
  2. There is the other question about the requestedRegion in vSlice[1]. why its index is [0,0,0] not [0,0,1]?
    Any help would be appreciated. Thanks.

requestedRegion is set by the programmer or by the consuming filter. I don’ think default index there is the problem.

And what exception do you get? You provided almost everything except that :smile:

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.

		RegionType region({ 0,0,0 }, { size [0],size [1],1});

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.

description about exception

I guess I did not pay attention to the topic title :slightly_frowning_face:

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:

tempImage->Allocate(true); // zero-initialize
for i:
  sliceI = ...
  tempImage = orFilter(tempImage, sliceI)

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.

except this one(setting all the region to same)

Maybe, but I don’t think it is worth the investigation.