-
Notifications
You must be signed in to change notification settings - Fork 92
Add conversion for BitType and BoolType imgs #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@gselzer This looks great to me, very clean and simple. I think it makes sense to put your tests in from jpype import JLong
jarray = JLong[:] @ [15, 20, 30]Instead of calling the |
70c03e9 to
fe46c6d
Compare
|
@gselzer It looks like I can't convert Operating in headless mode - the original ImageJ will have limited functionality.
Traceback (most recent call last):
File "Thread.java", line 829, in java.lang.Thread.run
java.lang.java.lang.ClassCastException: java.lang.ClassCastException: class net.imglib2.type.logic.BitType cannot be cast to class net.imglib2.type.logic.NativeBoolType (net.imglib2.type.logic.BitType and net.imglib2.type.logic.NativeBoolType are in unnamed module of loader 'app')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "OpEnvironment.java", line 136, in net.imagej.ops.OpEnvironment.run
java.util.concurrent.java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.lang.ClassCastException: class net.imglib2.type.logic.BitType cannot be cast to class net.imglib2.type.logic.NativeBoolType (net.imglib2.type.logic.BitType and net.imglib2.type.logic.NativeBoolType are in unnamed module of loader 'app')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "OpEnvironment.java", line 136, in net.imagej.ops.OpEnvironment.run
Exception: Java Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/edward/Documents/repos/loci/pyimagej/src/imagej/__init__.py", line 193, in from_java
return sj.to_python(data)
^^^^^^^^^^^^^^^^^^
File "/home/edward/Documents/repos/loci/scyjava/src/scyjava/_convert.py", line 553, in to_python
return _convert(data, py_converters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/edward/Documents/repos/loci/scyjava/src/scyjava/_convert.py", line 104, in _convert
return converter.convert(obj, **hints)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/edward/Documents/repos/loci/scyjava/src/scyjava/_convert.py", line 74, in convert
else self.converter(obj)
^^^^^^^^^^^^^^^^^^^
File "/home/edward/Documents/repos/loci/pyimagej/src/imagej/__init__.py", line 663, in <lambda>
converter=lambda obj: convert.java_to_ndarray(self._ij, obj),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/edward/Documents/repos/loci/pyimagej/src/imagej/convert.py", line 203, in java_to_ndarray
images.copy_rai_into_ndarray(ij, rai, narr)
File "/home/edward/Documents/repos/loci/pyimagej/src/imagej/images.py", line 166, in copy_rai_into_ndarray
ij.op().run("copy.rai", sj.to_java(narr), rai)
java.lang.java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.ClassCastException: class net.imglib2.type.logic.BitType cannot be cast to class net.imglib2.type.logic.NativeBoolType (net.imglib2.type.logic.BitType and net.imglib2.type.logic.NativeBoolType are in unnamed module of loader 'app') |
|
Hmm, fails on my machine too @elevans. Looks like the object
I'd prefer (1). |
|
This branch passes test successfully with |
elevans
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
fe46c6d to
bea175b
Compare
bea175b to
1b192f6
Compare
tests/test_image_conversion.py
Outdated
| ArrayImgs = sj.jimport("net.imglib2.img.array.ArrayImgs") | ||
| dims = JArray(JLong)(3) | ||
| dims[:] = [10, 10, 10] | ||
| dims = JLong[:] @ [10, 10, 10] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gselzer Better would be to use: sj.jarray('j', [10, 10, 10]) because then it doesn't depend on the JPype backend.
1b192f6 to
59fe36b
Compare
9ca58de to
52fcd71
Compare
|
@elevans I rewrote the support for imglib2 boolean types to only be present if the Ops version is there, however this is still smelly to me:
All of this is to say I'm not sure whether I like that last commit, so it's up to your discretion. |
|
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/39 |
|
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/41 |
7649b4a to
3f25216
Compare
This formatter converts the exceptions from copy_rai_into_ndarray into a
more human readable format.
**Before:**
Exception: (ClassCastException("class net.imglib2.type.logic.BitType cannot
be cast to class net.imglib2.type.logic.NativeBoolType (net.imglib2.type.logic.BitType
and net.imglib2.type.logic.NativeBoolType are in unnamed module of loader 'app')"),
ClassCastException("class net.imglib2.type.logic.BitType cannot be cast to class
net.imglib2.type.logic.NativeBoolType (net.imglib2.type.logic.BitType and
net.imglib2.type.logic.NativeBoolType are in unnamed module of loader 'app')"),
RuntimeException("java.util.concurrent.ExecutionException: java.lang.ClassCastException:
class net.imglib2.type.logic.BitType cannot be cast to class net.imglib2.type.logic.NativeBoolType
(net.imglib2.type.logic.BitType and net.imglib2.type.logic.NativeBoolType are in unnamed module
of loader 'app')"))
**After:**
Exception:
Error: Unsupported type cast via net.imglib2.util.ImgUtil.copy
Source type: net.imglib2.type.logic.BitType
Target type: net.imglib2.type.logic.NativeBoolType
Error: Unsupported type cast via net.imglib2.util.Images.copy
Source type: net.imglib2.type.logic.BitType
Target type: net.imglib2.type.logic.NativeBoolType
Error: Unsupported type cast via net.imagej.ops.copy.CopyNamespace.rai
Source type: net.imglib2.type.logic.BitType
Target type: net.imglib2.type.logic.NativeBoolType
c82eb45 to
a01f655
Compare
This time I'm more clever and look for the keywords "cannot" and "cast" in the exception string. Perhaps this will be more tolerant of slight variations of the exception stirng than relying on hard coded indices.
5444df1 to
7f26813
Compare
|
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/fiji-friends-weekly-dev-update-thread/103718/48 |
Using PyImageJ, functionality that returns boolean type images, like thresholds and morphology Ops, returns those images as images of
BitTypeand/orBoolType. PyImageJ normally converts these toDataArrays offloat64, which seems suboptimal.This change, utilizing imagej/imagej-ops#651, allows those
BitTypeand/orBoolTypeimages to become boolean arrays instead. Of course, we will need to wait for that PR to make its way into release before we can merge this PR.@elevans is there a better place to put the tests I wrote?