imagej / ImageJ

Public domain software for processing and analyzing scientific images
http://imagej.org
Other
513 stars 218 forks source link

Fix Roi setIntBounds widths #171

Closed hinerm closed 1 year ago

hinerm commented 1 year ago

Correct int bound width/height when the double bound ends in a decimal value >= 0.5

hinerm commented 1 year ago

@rasband when I was investigating https://github.com/imagej/imagej-legacy/issues/279 I noticed that the mentioned fix was now making Line.getBounds() too large when the Line was on midpoints. The following script demonstrates the behavior:

img = IJ.createImage("dec, dec", "8-bit noise", 200, 200, 1);
line = new Line(10.5, 10.5, 20.5, 20.5);
overlay = new Overlay();
overlay.add(line);
img.setOverlay(overlay);
b = line.getBounds();
rect = new Roi(b.x,b.y,b.width,b.height);
img.setRoi(rect);
img.show();

IJ.run(img, "To Selection", "");

img = IJ.createImage("int, int", "8-bit noise", 200, 200, 1);
line = new Line(10, 10, 20, 20);
overlay = new Overlay();
overlay.add(line);
img.setOverlay(overlay);
b = line.getBounds();
rect = new Roi(b.x,b.y,b.width,b.height);
img.setRoi(rect);
img.show();

IJ.run(img, "To Selection", "");

img = IJ.createImage("int, dec", "8-bit noise", 200, 200, 1);
line = new Line(10, 10, 20.5, 20.5);
overlay = new Overlay();
overlay.add(line);
img.setOverlay(overlay);
b = line.getBounds();
rect = new Roi(b.x,b.y,b.width,b.height);
img.setRoi(rect);
img.show();

IJ.run(img, "To Selection", "");

img = IJ.createImage("dec, int", "8-bit noise", 200, 200, 1);
line = new Line(10.5, 10.5, 20, 20);
overlay = new Overlay();
overlay.add(line);
img.setOverlay(overlay);
b = line.getBounds();
rect = new Roi(b.x,b.y,b.width,b.height);
img.setRoi(rect);
img.show();

IJ.run(img, "To Selection", "");

Here's a screenshot before this fix: image

And after:

image

hinerm commented 1 year ago

@hinerm Thanks for working on this. Did you also review the comment thread at imagej/imagej-legacy#279 (comment) ? Does this fix address all the cases?

This fix is unrelated to those test failures. Those were fixed by updating the expected values of the unit tests. Explanations in https://github.com/imagej/imagej-legacy/commit/c4f0b54dd2c31d274bf9e52c7ab1b0245f26757a and https://github.com/imagej/imagej-legacy/commit/45167258452629e442396062faeb537fc4df266d

ctrueden commented 1 year ago

@rasband Would you have time to roll this fix into ImageJ within the next few days?

rasband commented 1 year ago

This fix is in ImageJ 1.53t.

ctrueden commented 1 year ago

Thanks!

ctrueden commented 1 year ago

Fix merged as 9413b5e13e686bf485af6afd82d5ee6c3cb415ab.