Crop Error: Requested region is (at least partially) outside the largest possible region

Hello,

bounding_box = sw.ImageUtils.boundingBox(shape_seg_list, 0.5)
print(f"Bounding box: {bounding_box}")

for i, shape_seg in enumerate(shape_seg_list):
shape_seg.crop(bounding_box).pad(5,0)

ERROR:
shape_seg.crop(bounding_box).pad(5,0)
RuntimeError: C:\bdeps\ITK\Modules\Core\Common\src\itkDataObject.cxx:355:
Requested region is (at least partially) outside the largest possible region.

I tried printing the Spatial Coordinate Range of the shape_seg and it is not outside the global bounding_box, but it got an error, I don’t know why.

Thanks for your answer!!

Here is an example——

Bounding box: {
min: [-78.9304, -89.4858, -117.688],
max: [160.418, 85.762, 71.3125]
}

shape_seg Spatial Coordinate Range:
X: -175.0 to 174.125
Y: -175.0 to 174.125
Z: -124.6875 to 123.8125

shape_seg Bounding box: {
min: [-78.9304, -83.9446, -94.9375],
max: [157.59, 81.1488, 55.5625]
}

I don’t know what’s wrong ,but got an Error. It does not perform the ‘crop’ function properly.

In your case the bounding box Y coordinates go from -89.4858 to 85.762, but the image only goes from -83.9446 to 81.1488, so the crop size is larger than the image. For this crop function to work, the specified size must be entirely inside the image.

Thank you.
But actually the image Y coordinate goes from -175.0 to 174.125. What you say is just the Y coordinates of the image’s bounding box which comes from sw.ImageUtils.boundingBox([shape_seg], iso_value = 0.5)

Are there sample images you could share with me?

amorris@sci.utah.edu