imagej2 icon indicating copy to clipboard operation
imagej2 copied to clipboard

Wrong data for TIFF images

Open akidee opened this issue 7 years ago • 2 comments

Example:

ImagePlus img = new ImagePlus(tiffFile);
L.i(img.getWidth()+" x "+img.getHeight());
for (int i = 500; i < 600; i++) {
	int[] px = img.getPixel(i, i);
	out.println(i+": "+Arrays.toString(px));
}

Dimensions are always correct, data is correct for other image formats, but for TIFFs (here, 16 bit uncompressed) only the first channel shows values > 0, which is incorrect:

6000 x 4000
 500: [122, 0, 0, 0]
 501: [65325, 0, 0, 0]
 502: [65471, 0, 0, 0]
 503: [28, 0, 0, 0]
 504: [65202, 0, 0, 0]
 505: [65281, 0, 0, 0]
 506: [65021, 0, 0, 0]

How can I get correct values?

akidee avatar Oct 15 '18 15:10 akidee

Firstly, please be aware that this repository is for ImageJ2. You are using the ImageJ1 API, so this issue would fit best at https://github.com/imagej/imagej1. It is not a big deal—we do not have to move it—but I just want to make sure you are aware that there are two different APIs, so that the following information makes more sense.

This might be a bug in the ImageJ1 TIFF reader. You can try opening your TIFF the ImageJ2 way. Here is a Groovy script usable from ImageJ's Script Editor:

#@ DatasetIOService io
image = io.open(tiffFile)
access = image.randomAccess()
for (int i = 500; i < 600; i++) {
	access.setPosition(i, 0)
	access.setPosition(i, 1)
	println(i+": "+access.get())
}

If you need standalone Java code, it can be done like this:

import net.imagej.Dataset;
import net.imagej.ImageJ;
import net.imglib2.RandomAccess;
import java.io.IOException;

public class TIFFExplorer {
	public static void main(final String... args) throws IOException {
		ImageJ ij = new ImageJ();
		String tiffFile = "/path/to/my.tif";
		Dataset image = ij.scifio().datasetIO().open(tiffFile);
		RandomAccess<?> access = image.randomAccess();
		for (int i = 500; i < 600; i++) {
			access.setPosition(i, 0);
			access.setPosition(i, 1);
			System.out.println(i + ": " + access.get());
		}
		ij.context().dispose();
	}
}

If the ImageJ2 way also gives the wrong pixel values, then please post your TIFF online so that we can inspect it.

ctrueden avatar Oct 15 '18 16:10 ctrueden

Thanks for the hint. I consider posting it there later.

Now I have a problem with the dependency in Gradle on ./gradlew build:

Could not resolve all dependencies for configuration ':compileClasspath'.

Could not find net.imagej:imagej:2.0.0-rc-59. Searched in the following locations: https://repo1.maven.org/maven2/net/imagej/imagej/2.0.0-rc-59/imagej-2.0.0-rc-59.pom https://repo1.maven.org/maven2/net/imagej/imagej/2.0.0-rc-59/imagej-2.0.0-rc-59.jar https://jcenter.bintray.com/net/imagej/imagej/2.0.0-rc-59/imagej-2.0.0-rc-59.pom https://jcenter.bintray.com/net/imagej/imagej/2.0.0-rc-59/imagej-2.0.0-rc-59.jar

2.0.0-rc-1 will fail, too.

akidee avatar Oct 16 '18 02:10 akidee