Closed sudgy closed 4 years ago
This is an issue of imagej1
.
The reason is likely mask
being null
at the reported line here:
Rectangular ROIs seem to return null
for their getMask()
method, as shown by this Groovy script:
import ij.gui.OvalRoi
roi = new OvalRoi(0,0,10,10)
println roi.getMask() // ip[width=10, height=10, bits=8, min=0.0, max=255.0]
import ij.gui.Roi
roi = new Roi(0,0,10,10)
println roi.getMask() // null
@rasband any comments?
getMask() returns null because Rectangular ROIs do not need a mask. Here is the code for Roi.getMask():
/** Always returns null for rectangular Roi's */
public ImageProcessor getMask() {
if (cornerDiameter>0)
return (new ShapeRoi(new RoundRectangle2D.Float(x, y, width, height, cornerDiameter, cornerDiameter))).getMask();
else
return null;
}
Thanks @rasband for the quick reply. I see the point why rectangular ROIs don't need a mask. Nevertheless, the original issue – that iterating over all points inside the ROI throws an exception – is not yet solved, so I reopen this issue.
This bug is fixed in the ImageJ 1.52s5 daily build. The Roi Iterator now creates the mask needed to iterate over the points in a rectangular ROI. Code changes are at https://github.com/imagej/imagej1/commit/a8cb324b96c40bfbc843809a8d625371fee3504e
When a user selects a rectangular ROI, and then code calls the ImagePlus' getRoi() and tries to iterate over it, the code throws a NullPointerException. Here is a simple plugin that can be used to reproduce the bug:
The interesting thing is that this only crashes when a rectangular ROI is selected. With any other type of ROI, it works correctly.