You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ShapeRoi handles "open" ("line-like") rois incorrectly, most notably
when performing set arithmetic using functions such as or() (union),
or and() (intersection) (and others). The root cause of this is that ShapeRoi delegates set arithmetic to java.awt.geom.Area and Area
explicitly limits itself to representing "an enclosed area of 2-dimensional
space."
(The ShapeRoi (Shape) constructor presumably suffers from an analogous
issue, and a similar fix is likely to work. Also, RoiManager performs
significant preprocessing before delegating some of the set arithmetic
it performs to ShaepRoi. It would make sense to fix ShapeRoi properly,
and then have RoiManager delegate all of its set arithmetic directly to ShapeRoi without any non-trivial preprocessing.)
Here is a link to a contemporaneous forum thread that further discusses
this issue and the proposed fix:
The core issue is illustrated by the following test script:
fromij.guiimportLinefromij.guiimportPolygonRoifromij.guiimportRoifromij.guiimportShapeRoirect=Roi (0, 0, 20, 20)
sr_rect=ShapeRoi (rect)
# goodprint'len (rect.getContainedPoints()) =', len (rect.getContainedPoints())
# goodprint'len (sr_rect.getContainedPoints()) =', len (sr_rect.getContainedPoints())
sr_rect_or_rect=sr_rect.or (ShapeRoi (Roi (0, 30, 20, 20)))
# goodprint'len (sr_rect_or_rect.getContainedPoints()) =', len (sr_rect_or_rect.getContainedPoints())
line=Line (0, 0, 20, 0)
sr_line=ShapeRoi (line)
# goodprint'len (line.getContainedPoints()) =', len (line.getContainedPoints())
# wrong -- getContainedPoints is emptyprint'len (sr_line.getContainedPoints()) =', len (sr_line.getContainedPoints())
sr_line_or_line=sr_line.or (ShapeRoi (Line (0, 10, 20, 10)))
# wrong -- conversion to Area in or() causes Line to vanish entirelyprint'len (sr_line_or_line.getContainedPoints()) =', len (sr_line_or_line.getContainedPoints())
polyline=PolygonRoi ([0, 10, 10], [0, 0, 10], Roi.POLYLINE)
sr_polyline=ShapeRoi (polyline)
# goodprint'len (polyline.getContainedPoints()) =', len (polyline.getContainedPoints())
# wrong -- ShapeRoi acts like the interior of a closed triangleprint'len (sr_polyline.getContainedPoints()) =', len (sr_polyline.getContainedPoints())
sr_polyline_or_polyline=sr_polyline.or (ShapeRoi (PolygonRoi ([0, 10, 10], [20, 20, 30], Roi.POLYLINE)))
# wrong -- conversion to Area still acts like the interior of a closed triangleprint'len (sr_polyline_or_polyline.getContainedPoints()) =', len (sr_polyline_or_polyline.getContainedPoints())
The output of the script (run with ImageJ 2.0.0-rc-69/1.52p;
Java 1.8.0_172 [64-bit]) is:
len (rect.getContainedPoints()) = 400
len (sr_rect.getContainedPoints()) = 400
len (sr_rect_or_rect.getContainedPoints()) = 800
len (line.getContainedPoints()) = 21
len (sr_line.getContainedPoints()) = 0
len (sr_line_or_line.getContainedPoints()) = 0
len (polyline.getContainedPoints()) = 21
len (sr_polyline.getContainedPoints()) = 45
len (sr_polyline_or_polyline.getContainedPoints()) = 90
The proposed fix for this issue is to modify ShapeRoi.roiToShape() so
that it converts any line-like Roi into an Area composed of rectangles,
one for each point (pixel) in the original Roi. (This is what roiToShape()
already does for PointRoi.)
Here is the substantive part of the fix to ShapeRoi.roiToShape():
If people think this makes sense, my plan would be to solicit input
from interested parties, finish a more complete version of a fixed
ShapeRoi.java, and make it available for further testing and review.
The text was updated successfully, but these errors were encountered:
See my reply on the forum. I think it makes more sense to use the latest ImgLib2 ROI library, rather than potentially breaking backwards compatibility of existing ImageJ1 extensions.
ShapeRoi
handles "open" ("line-like") rois incorrectly, most notablywhen performing set arithmetic using functions such as
or()
(union),or
and()
(intersection) (and others). The root cause of this is thatShapeRoi
delegates set arithmetic tojava.awt.geom.Area
andArea
explicitly limits itself to representing "an enclosed area of 2-dimensional
space."
(The
ShapeRoi (Shape)
constructor presumably suffers from an analogousissue, and a similar fix is likely to work. Also,
RoiManager
performssignificant preprocessing before delegating some of the set arithmetic
it performs to
ShaepRoi
. It would make sense to fixShapeRoi
properly,and then have
RoiManager
delegate all of its set arithmetic directly toShapeRoi
without any non-trivial preprocessing.)Here is a link to a contemporaneous forum thread that further discusses
this issue and the proposed fix:
https://forum.image.sc/t/proposed-fix-for-shaperoi-issue/29391
Here is an earlier forum thread about this issue:
https://forum.image.sc/t/shaperoi-or-and-shaperoi-getcontainedpoints-fail-with-line-line-roi/27964
The core issue is illustrated by the following test script:
The output of the script (run with ImageJ 2.0.0-rc-69/1.52p;
Java 1.8.0_172 [64-bit]) is:
The proposed fix for this issue is to modify
ShapeRoi.roiToShape()
sothat it converts any line-like
Roi
into anArea
composed of rectangles,one for each point (pixel) in the original
Roi
. (This is whatroiToShape()
already does for
PointRoi
.)Here is the substantive part of the fix to
ShapeRoi.roiToShape()
:If people think this makes sense, my plan would be to solicit input
from interested parties, finish a more complete version of a fixed
ShapeRoi.java, and make it available for further testing and review.
The text was updated successfully, but these errors were encountered: