Skip to content
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

Map namespace methods type safety #612

Open
Xanthorapedia opened this issue Aug 8, 2019 · 1 comment
Open

Map namespace methods type safety #612

Xanthorapedia opened this issue Aug 8, 2019 · 1 comment

Comments

@Xanthorapedia
Copy link

When I was trying to copy an image converted with LUT to a freshly created Img, the following happens:

RandomAccessibleInterval<FloatType> floatImg = ArrayImgs.floats(128, 128);
RandomAccessibleInterval<ARGBType>  argbRAI = Converters.convert(floatImg, new RealLUTConverter<FloatType>(0, 1, ColorTables.GRAYS), new ARGBType());
Img<ARGBType> argbImg = ArrayImgs.argbs(128, 128);
ops.copy().rai(argbImg, argbRAI);

Output:

net.imglib2.converter.read.ConvertedRandomAccessibleInterval cannot be cast to net.imglib2.IterableInterval

java.lang.ClassCastException: net.imglib2.converter.read.ConvertedRandomAccessibleInterval cannot be cast to net.imglib2.IterableInterval
	at net.imagej.ops.map.MapUnaryComputers$IIToIIParallel.compute(MapUnaryComputers.java:87)
	at net.imagej.ops.copy.CopyRAI.compute(CopyRAI.java:90)
	at net.imagej.ops.copy.CopyRAI.compute(CopyRAI.java:54)
	at net.imagej.ops.special.hybrid.UnaryHybridCF.run(UnaryHybridCF.java:75)
	at net.imagej.ops.special.hybrid.UnaryHybridCF.run(UnaryHybridCF.java:97)
	at org.scijava.command.CommandModule.run(CommandModule.java:199)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:950)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:157)
	at net.imagej.ops.copy.CopyNamespace.rai(CopyNamespace.java:167)
	...

The cause seems to me that while matching ops, a ConvertedRandomAccessibleInterval is recognized as directly convertible to an II in DefaultOpMatchingService.canConvert() and this leads the op service to believe that IIToIIParallel is a suitable op for the task. I haven't dug deeper than that. Any insights?

@Xanthorapedia Xanthorapedia changed the title Op matching for copy.rai(RAI, RAI) Namespace methods type safety Jul 30, 2020
@Xanthorapedia Xanthorapedia changed the title Namespace methods type safety Map namespace methods type safety Jul 30, 2020
@Xanthorapedia
Copy link
Author

The problem seems to be that when CopyRAI is looking for suitable computers, IIToIIParallel instead of IIToRAIParallel is selected since the second argument can be cast into II, which outputs an II instead of RAI.

A similar problem occurs when calling ops.map() with arguments being both II and RAI but cast into RAI. The selected method signature is map(RAI, RAI) -> RAI, but op matching always returns IIToII-ish ops, which returns an II.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant