These are chat archives for fiji/fiji

17th
Aug 2016
Hadrien Mary
@hadim
Aug 17 2016 13:42
Hey guys. New question about crop. When I try to crop something outside of the image I got a java.lang.RuntimeException: java.lang.RuntimeException: Intervals don't match! error. Make sense.
Do you think it could be usefull to add an option to return black pixel when they are outside of the image instead of returning an error ?
Stefan Helfrich
@stelfrich
Aug 17 2016 13:43
@hadim What exactly do you mean by "crop something outside of the image"?
Hadrien Mary
@hadim
Aug 17 2016 13:43
For example when the interval start in the image but end outside of the dimension of the image.
Stefan Helfrich
@stelfrich
Aug 17 2016 13:44
Ah ok. You should then use an OutOfBoundsStrategy that assigns 0 to outside pixels I guess..
Views.extendZero(input)
and then crop this..
Are you "cropping" with Views.interval()?
Hadrien Mary
@hadim
Aug 17 2016 13:45
ops.transform().crop()
Stefan Helfrich
@stelfrich
Aug 17 2016 13:46
Should work as well..
Hadrien Mary
@hadim
Aug 17 2016 13:46
I got this error TypeError: crop(): 1st arg can't be coerced to net.imglib2.RandomAccessibleInterval, net.imagej.ImgPlus
using Views.extendZero(img) img being an ImgPlus
Stefan Helfrich
@stelfrich
Aug 17 2016 13:47
that's weird..
You can also use ops.transform().extendZero() btw
Hadrien Mary
@hadim
Aug 17 2016 13:47
It works well with only img
Stefan Helfrich
@stelfrich
Aug 17 2016 13:47
Ah yes
Hadrien Mary
@hadim
Aug 17 2016 13:47
Same error with ops.transform().extendZero()
Stefan Helfrich
@stelfrich
Aug 17 2016 13:48
the extend* methods don't return a RAI
they need an interval afterwards
Views.interval(Views.extendZero(input), input)
Hadrien Mary
@hadim
Aug 17 2016 13:48
ImgPlus are RAI with interval ?
Stefan Helfrich
@stelfrich
Aug 17 2016 13:48
that will extend with zero outside of the interval of input
Yes, they are
Hadrien Mary
@hadim
Aug 17 2016 13:50
Ok so when I crop using this cropped_img = ops.transform().crop(Views.interval(Views.extendZero(img), img), intervals) I still have the java.lang.RuntimeException: java.lang.RuntimeException: Intervals don't match! error.
Stefan Helfrich
@stelfrich
Aug 17 2016 13:50
But ExtendedRandomAccessibleInterval as returned by the extend* methods only implements RandomAccessible not RAI
Hadrien Mary
@hadim
Aug 17 2016 13:50
Ok
Stefan Helfrich
@stelfrich
Aug 17 2016 13:51
Oh, what about the dimensions?
img.numDimensions() == intervals.numDimensions()?
Hadrien Mary
@hadim
Aug 17 2016 13:51
Same
2 for both
This message was deleted
# @Dataset ds
# @OpService ops
# @DatasetService datasetService
# @ImageJ ij

from net.imglib2.util import Intervals
from net.imglib2.view import Views

img = ds.getImgPlus()

intervals = Intervals.createMinMax(363, 136, 499, 167)
#intervals = Intervals.createMinMax(363, 136, 399, 167)

print(img.numDimensions())
print(intervals.numDimensions())

cropped_img = ops.transform().crop(Views.interval(Views.extendZero(img), img), intervals)

final_dataset = datasetService.create(cropped_img)
ij.ui().show(final_dataset)
I use this script with Cell Colony sample.
Stefan Helfrich
@stelfrich
Aug 17 2016 13:53
I found the problem
let me investigate that for a moment
Hadrien Mary
@hadim
Aug 17 2016 13:53
Yep sure.
Thank you and tell me if I can do anything to help.
It seems like this is not an intended use case :worried: I don't know why, though, off the top of my head
Hadrien Mary
@hadim
Aug 17 2016 13:55
:-(
Let's see what @ctrueden think about that.
But I think we should be able to do that.
Stefan Helfrich
@stelfrich
Aug 17 2016 13:56
You could do Intervals.intersect(img, intendedInterval)
and feed that to the crop op
but that's really just working around the issue
Hadrien Mary
@hadim
Aug 17 2016 13:57
Ok. Thank you.
Stefan Helfrich
@stelfrich
Aug 17 2016 14:01
More guessing from my side: we currently can't robustly figure out if an input is extended. this, however, is a prerequisite for what you are trying to do. otherwise you wouldn't be able to access pixels in the region that was not covered by the original interval of the input image.
You can also do Views.offsetInterval(Views.interval(Views.extendZero(img), img), intervals) (which is what the crop op does internally)
Curtis Rueden
@ctrueden
Aug 17 2016 15:02

we currently can't robustly figure out if an input is extended

But we discussed a plan for being able to do so, at the last hackathon, did we not? (Sorry, details are fuzzy for me now.)

@hadim One general point: you can try ops.run("transform.crop", ...) instead of ops.transform().crop(...) and see if it makes a difference.
That is: Ops supports auto-magical conversion of types, beyond what can be done by casting, and so it is often possible to pass non-matching (typewise) arguments to a particular op and have things still magically work. But only if you use ops.run.
We used to have Object... sigs for all ops—e.g., ops.transform().crop(Object...)—but they wreaked havoc with the compiler because then every list of args you try to pass always matches. So we removed them. My plan is to readd them, but somewhere else—i.e., not mixed in with the type-safe sigs.
Stefan Helfrich
@stelfrich
Aug 17 2016 15:10
We talked about that @ctrueden. That's a good point to ping @tpietzsch on the definedBounds. Do you have news on that, Tobi?