Img2lib2 FinalInterval width

Hello,

@tpietzsch

I need to specify an N-D data cube in an image.

I found the FinalInterval class in imglib2 to do this. However for some parts of my code I need get the width of the interval along a certain dimension, thus something like a getWidth( d ) would be good.

Right now I have to do

interval.max(d) - interval.min(d) + 1

which is a bit cumbersome. Is there another implementation of Interval that does give the width directly?

1 Like

Interval extends Dimensions. You can use dimension(d).

4 Likes

awesome. thanks! I am really getting into imglib2 now :slight_smile:

4 Likes

@tpietzsch, may I have another related question?!
Is there also a nicer way to loop over one dimension of the interval?
right now I am doing, e.g. like this:

final int C = 3; // my channel dimension, for example

for ( int c = (int) interval.min( C ); c <= interval.max( C ); ++c ) 

Is there something like below? I found the IntervalIterator class but I don’t understand how to use it to iterate through only one dimension of an existing multi-dimensional interval.

for ( int c : interval.dimensionIterator( C ) )

No, theres nothing like that. You will have to use something like the for ( int c = (int) interval.min( C ); c <= interval.max( C ); ++c ) you suggested.

In the end, it depends on what you want to do with c
If you want to iterate over c-slices. you could use Views.hyperslices followed by Views.interval for example. Sometimes IntervalIterator might be the right thing. It depends …

2 Likes