Imglib2 localneighborhood within bounds

Hello,

I was wondering whether there is an imglib2 localNeighborhood that stays within the image bounds. Essentially, I would like to use no outOfBounds Strategy, but simply get less pixels in the neighborhood if I am close to the image boundary.

Best,
Christian.

2 Likes

Hi Christian,

I don’t know of a direct method, and I’m grasping at straws here, but one hacky way to do it would be to call Views.extendValue(interval, specialValue) where specialValue could be Double.NaN or other such value your elements wouldn’t usually have. Then you could just filter out the elements with specialValue.

Best regards,
Richard

2 Likes

Hi @Christian_Tischer,

I’m fairly confident such a localNeighborhood does not exist in imglib2 at the moment. Imglib2 prioritizes performance. See this issue where @ctrueden talks about the bounds-checking vs performance tradeoff.

https://github.com/imglib/imglib2/issues/170

I’m not sure what the right solution is for you - depends on what you’re doing with the neighborhood.
You could do the check yourself, but do keep in mind that there will be a hit to performance.

John

Thank you @bogovicj and @rimadoma!

In this case, as I am anyway still mostly living in the ImagePlus world, I think it is maybe easiest for me to just write a rectangleWithinBoundsNeighborhood function myself.

Cheers, Christian

2 Likes