Looks like a bug in CooccurenceMatrix3D

imagej-ops
Tags: #<Tag:0x00007fd69ccd2ad8>

#1

I see what looks like a bug in
//github.com/imagej/imagej-ops/blob/master/src/main/java/net/imagej/ops/image/cooccurrenceMatrix/CooccurrenceMatrix3D.java

It is OK in 2D but in 3D, there is a missing check on pixels[sz][sy][sx] != Integer.MAX_VALUE.
I have added it below:

	for (int z = 0; z < pixels.length; z++) {
		for (int y = 0; y < pixels[z].length; y++) {
			for (int x = 0; x < pixels[z][y].length; x++) {

				// ignore pixels not in mask
				if (pixels[z][y][x] == Integer.MAX_VALUE) {
					continue;
				}

				// get second pixel
				final int sx = (int) (x + orientationAtX);
				final int sy = (int) (y + orientationAtY);
				final int sz = (int) (z + orientationAtZ);

				// second pixel in interval and mask
				if (sx >= 0 && sy >= 0 && sz >= 0 && sz < pixels.length
						&& sy < pixels[sz].length
						&& sx < pixels[sz][sy].length
						&& pixels[sz][sy][sx] != Integer.MAX_VALUE) {

					matrix[pixels[z][y][x]][pixels[sz][sy][sx]]++;
					nrPairs++;
				}
			}
		}
	}

Please let me know if I am missing something.
Ilan


#2

@ilan

It’s best if you could file an issue in that repo then… and link this Forum post. That would be ideal for this to be addressed and also documented.

eta


#3

The issue is now posted. Thanks.


#4

Issue filed at imagej-ops#522 and fixed. Will be included in the next imagej-ops release.