One fun workaround might be a variant of this code or the variety of scripts here that uses the getArea functions based off of one of Pete’s scripts.
If you are pairwise checking every two objects, and you add their Areas (not their areas ), the result should only be the same size as the smaller of the two objects if one is contained within the other.
By that logic I quickly hacked off a part of Pete’s script and got:
The script itself takes an annotation, expands it by a set amount, and then tests adding the original and expanded areas together. Due to the first area being entirely inside the second, they have the same final “area” once being converted back into an ROI. At no point do I actually do any creating of this ROI object I was using for testing.
Probably not necessary, but as a reference, here’s the code. And so Pete can pick out any potential flaws in my logic.
def server = getCurrentImageData().getServer()
double expandMarginMicrons = 300
double expandPixels = expandMarginMicrons / server.getAveragedPixelSizeMicrons()
def selected = getSelectedObject()
def roiOriginal = selected.getROI()
println "Starting ROI Area " + roiOriginal.getArea()
def areaTumor = PathROIToolsAwt.getArea(roiOriginal)
def areaOuter = PathROIToolsAwt.shapeMorphology(areaTumor, expandPixels)
def roiOuter = PathROIToolsAwt.getShapeROI(areaOuter, roiOriginal.getC(), roiOriginal.getZ(), roiOriginal.getT())
println "Expanded ROI Area " + roiOuter.getArea()
def testForInside = PathROIToolsAwt.getShapeROI(areaOuter, roiOriginal.getC(), roiOriginal.getZ(), roiOriginal.getT())
println "Sum of two Area objects "+testForInside.getArea()
Slightly more complex area.
Intended failed area