-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add converters between ImgLib2 RAI and ImageJ1 ImagePlus #229
Comments
I guess this can be done with the new Which conversions need to be supported explicitly?
|
I think the delegate converter will be useful, yeah. Thanks for developing it. For new converters needed:
The above is just speculative—best would be to do some thorough TDD requesting all sorts of anticipated desirable conversions, and then implement the most general converters that also minimize information loss. |
For the record, this Groovy script lists current support for some of the conversions: #@ ConvertService cs
import ij.ImagePlus
import net.imagej.Dataset
import net.imagej.ImgPlus
import net.imglib2.img.Img
import net.imglib2.RandomAccessibleInterval
println cs.supports(Dataset.class, ImagePlus.class) // true
println cs.supports(Dataset.class, ImgPlus.class) // true
println cs.supports(Dataset.class, Img.class) // true
println cs.supports(Dataset.class, RandomAccessibleInterval.class) // true
println ""
println cs.supports(ImagePlus.class, Dataset.class) // true
println cs.supports(ImagePlus.class, ImgPlus.class) // false
println cs.supports(ImagePlus.class, Img.class) // true
println cs.supports(ImagePlus.class, RandomAccessibleInterval.class) // true
println ""
println cs.supports(ImgPlus.class, Dataset.class) // false
println cs.supports(ImgPlus.class, ImagePlus.class) // false
println cs.supports(ImgPlus.class, Img.class) // true
println cs.supports(ImgPlus.class, RandomAccessibleInterval.class) // true
println ""
println cs.supports(Img.class, Dataset.class) // false
println cs.supports(Img.class, ImagePlus.class) // false
println cs.supports(Img.class, ImgPlus.class) // true
println cs.supports(Img.class, RandomAccessibleInterval.class) // true
println ""
println cs.supports(RandomAccessibleInterval.class, Dataset.class) // false
println cs.supports(RandomAccessibleInterval.class, ImagePlus.class) // false
println cs.supports(RandomAccessibleInterval.class, ImgPlus.class) // false
println cs.supports(RandomAccessibleInterval.class, Img.class) // false |
I started implementing a parameterized test in fb75ae4, where different types and axis orders can be defined to be tested in |
See also imagej/imagej-common#74 |
This issue has been mentioned on Image.sc Forum. There might be relevant details there: |
This issue has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/save-ilastik-hdf5-files-from-java/60194/2 |
I wrote a more thorough script printing supported conversions: image-conversions.py#@ ConvertService cs
import sys
from ij import ImagePlus
from net.imagej import Dataset, ImgPlus
from net.imagej.display import DatasetView, ImageDisplay
from net.imglib2.img import Img
from net.imglib2 import RandomAccessibleInterval
image_types = [
ImagePlus,
RandomAccessibleInterval,
Img,
ImgPlus,
Dataset,
DatasetView,
ImageDisplay,
]
sys.stdout.write(" ")
for col in image_types:
sys.stdout.write("{0: <13}".format('RAI' if col == RandomAccessibleInterval else col.__name__))
print
for row in image_types:
sys.stdout.write("{0: <14}".format('RAI' if row == RandomAccessibleInterval else row.__name__))
for col in image_types:
sys.stdout.write("yes " if cs.supports(col, row) else "NO ")
print And the results as of this writing:
The PyImageJ and napari-imagej projects have to bend over backwards to support image conversions that aren't supported by the |
* Dataset -> DatasetView * RandomAccessibleInterval -> ImageDisplay See also imagej/imagej-legacy#229. Co-authored-by: Curtis Rueden <ctrueden@wisc.edu>
imagej/imagej-common#102 adds new converters for Dataset to DatasetView and RAI to ImageDisplay. Updated table:
|
[CTR: There is one failing test... due to how SingleInputPreprocessors work. They eagerly try to convert. Now that this commit adds so many converters, we get a situation where e.g. the ActiveDatasetPreprocessor takes precedence over the ActiveImageDisplayPreprocessor when filling single ImageDisplay parameters, which is obviously bad... blargh.] This work is a major step toward resolving imagej/imagej-legacy#229, but does not quite do the entire job, since ij.ImagePlus is another image type on that list, which is not available from imagej-common. But we can add converters to imagej-legacy for ImagePlus to+from all other image types, and then we'll have everything covered. See also imagej/imagej-ops#54.
This work is a major step toward resolving imagej/imagej-legacy#229, but does not quite do the entire job, since ij.ImagePlus is another image type on that list, which is not available from imagej-common. But we can add converters to imagej-legacy for ImagePlus to+from all other image types, and then we'll have everything covered. See also imagej/imagej-ops#54. Note that these new converters triggered one failing test, SingleInputPreprocessorTest#testSingleImageDisplay, because the ActiveDatasetPreprocessor was getting a chance to fill the single ImageDisplay parameter before the ActiveImageDisplayPreprocessor did, and so the ActiveDatasetPreprocessor would wrap the active Dataset into a *new ImageDisplay* via the newly added DatasetToImageDisplayConverter. To avoid this issue, this commit bumps up the priorities of certain SingleInputPreprocessors: ActiveImageDisplayPreprocessor highest, then ActiveDatasetViewPreprocessor, then ActiveDataViewPreprocessor, then ActiveDatasetPreprocessor. This adjustment results in all the tests passing, but we will need to continue to be careful about the SingleInputPreprocessor ordering. As things stand, there is probably still some surprising behavior under the hood, because now when there is a single Dataset input, it will be the ActiveImageDisplayPreprocessor that fills it by unwrapping that Dataset from itself via the ImageDisplayToDatasetConverter. We could consider removing a bunch of no-longer-necessary SingleInputPreprocessor implementations, but for now, I am choosing not to rock the boat further.
With imagej/imagej-common#103, and specifically imagej/imagej-common@e67b5c9, I have now coded converters for all image types to/from all others, except for |
This issue has been mentioned on Image.sc Forum. There might be relevant details there: |
There are converters for
Dataset
to/fromImagePlus
(though see #186). But if you have e.g. anArrayImg
, you cannot currently convert it directly toImagePlus
with theConvertService
. We want this to be possible.The text was updated successfully, but these errors were encountered: