generate_spatial_bounding_box: upper bound inclusive? #7477
-
I have a binary image volume with non empty sagittal slices ranging from slice 3 to slice 187 (starting from 0). So I'd expect the bounding box to be ([3, X, X], [187, X, X]) but I get 188 instead of 187 which is an empty slice. The description states: "Generate the spatial bounding box of foreground in the image with start-end positions (inclusive)." What am I missing? Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @crossmanith, thanks for your interest here. The bounding box generated is likely configured to use an exclusive end index, which is a common approach in Python. This means that for an array of size N, the indices would actually start at 0 and end at N-1 for inclusive indexing. Given your example, where you have non-empty sagittal slices ranging from slice 3 (inclusive) to slice 187 (inclusive), the bounding box is correctly starting at 3. The end index being 188 is also correct if we're considering exclusive indexing because 188 would be the first empty slice after your filled data. This 188 is an exclusive index, so that index is not included. It's the index "up to but not including" which is similar to the behavior of range, slicing in python etc. Thus it seems there's a discrepancy in the docstring, I agree that the phrasing "with start-end positions (inclusive)" can confuse. I will create a PR to update it, thanks. |
Beta Was this translation helpful? Give feedback.
Hi @crossmanith, thanks for your interest here.
The bounding box generated is likely configured to use an exclusive end index, which is a common approach in Python. This means that for an array of size N, the indices would actually start at 0 and end at N-1 for inclusive indexing.
Given your example, where you have non-empty sagittal slices ranging from slice 3 (inclusive) to slice 187 (inclusive), the bounding box is correctly starting at 3. The end index being 188 is also correct if we're considering exclusive indexing because 188 would be the first empty slice after your filled data. This 188 is an exclusive index, so that index is not included. It's the index "up to but not including"…