Hi all,

With ImgLib2’s `AffineTransform3D`

, when I transform a volume (meaning, I first extend it with zero-padding, then wrap it with a linear interpolation, and then view it as transformed), then, in order to view the transformed volume an `Interval`

must be defined. What’s the maximum containing interval? Do I have to transform the coordinates of all its corners and then compute the new enclosing maximal `Interval`

by myself, or is there a util method somewhere that does this?

Thanks.

2 Likes

See this related GitHub issue and discussion:

1 Like

Thanks, looks like there’s an identified missing library function yet the issue has been stagnant since 2017.

2 Likes

Steal this if you’d like:

It transforms all corners of an interval and outputs the smallest bounding interval.

John

1 Like

It would be great to have something like this available in a utility class of ImgLib2 indeed .

1 Like

Thanks @bogovicj ! I second @imagejan: make this a library function in imglib2.

For jython, I wrote something much shorter:

```
from net.imglib2 import FinalInterval
from net.imglib2.util import Intervals
import sys
from itertools import repeat, product
from math import ceil, floor
from jarray import zeros
affine = ... # e.g. an imglib2 AffineTransform3D
img = ...
bounds = repeat((sys.maxint, 0)) # initial upper- and lower-bound values for min, max to compare against
transformed = zeros(img.numDimensions(), 'f')
for corner in product(*zip(repeat(0), Intervals.maxAsLongArray(img))):
affine.apply(corner, transformed)
bounds = [(min(vmin, int(floor(v))), max(vmax, int(ceil(v))))
for (vmin, vmax), v in zip(bounds, transformed)]
minC, maxC = map(list, zip(*bounds)) # transpose list of lists
interval = FinalInterval(minC, maxC)
```

See the full example here in the Fiji python tutorial.

1 Like