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

Signed integer Img is displayed incorrectly by ImageJFunctions.show #13

Open
mountain-maennlein opened this issue Feb 9, 2018 · 1 comment

Comments

@mountain-maennlein
Copy link

When displaying an IJ2 Img, say, img, of signed integral type, e.g., ByteType or IntType,
ImageJFunctions.show (img, "title"); renders negative values as zero.

This issue is also discussed in two imagej forum topics:
Signed integer Img is displayed incorrectly by ImageJFunctions.show
and
Is there a pure IJ2 mechanism for displaying images using stock Fiji?

This is presumably due to the fact that IJ1 appears not support signed integral images.
(It does support a floating-point GRAY32 image type.)

Other IJ2 Img display methods, such as DisplayService.show ("title", img); appear
to convert the signed integral Img to a FloatType / float32 Img before handing it
off to IJ1, which then displays it (correctly) as a GRAY32 image.

As long as IJ2 continues (at least in some contexts) to rely on IJ1 for image display,
the best fix would be to add signed integral display functionality to IJ1. This would
avoid the cost in time and space of the ByteType (etc.) --> FloatType conversion.
Such a fix can be arranged to be non-breaking because it only adds new functionality
to IJ1.

A more expedient fix would be to have ImageJFunctions.show mimic
DisplayService.show, and first convert signed integral images to FloatType
images before displaying them with IJ1. (Of course, if signed integral display
were added to IJ1, DisplayService.show, and similar, should be updated to
use it, as well.)

@ctrueden
Copy link
Member

ctrueden commented May 25, 2018

I tested just now with the new imglib2-ij 2.0.0-beta-41 release, which includes @maarzt's work from #12. This issue still persists.

Consider the following Groovy script:

import net.imglib2.img.array.ArrayImgs
import net.imglib2.img.display.imagej.ImageJFunctions
byte[] data = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13]
byteImg = ArrayImgs.bytes(data, [6, 4] as long[])
ImageJFunctions.show(byteImg)

The following image is produced:
screen shot 2018-05-25 at 13 09 19
With negative values all truncated to zero.

the best fix would be to add signed integral display functionality to IJ1.

ImageJ1 does support signed integer values already, to an extent. It does so via its "calibration" feature: Analyze ▶ Calibrate...; see here for an overview; enter Linear Scale and then uncalibrated example values on the left and their corresponding calibrated/adjusted values on the right. ImageJ1 supports calibration functions for uint8 and uint16. For larger integer types, we need to wrap as float32 regardless.

We should update this library to generate properly calibrated ImagePlus objects when there are negative values.

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

No branches or pull requests

2 participants