Example #1
0
def calculate_mean_r(imp, ring_rois, centres):
    """calculate the average distance of the cell surface from the vessel axis"""
    w = imp.getWidth()
    h = imp.getHeight()
    rp = FloatProcessor(w, h)
    rpix = rp.getPixels()
    for lidx, (roi, centre) in enumerate(zip(ring_rois, centres)):
        for thetaidx, (x, y) in enumerate(
                zip(roi.getPolygon().xpoints,
                    roi.getPolygon().xpoints)):
            rpix[lidx * w + thetaidx] = math.sqrt((x - centre[0])**2 +
                                                  (y - centre[1])**2)
    rimp = ImagePlus("Radii", rp)
    IJ.setAutoThreshold(rimp, "Intermodes light")
    bp = rimp.createThresholdMask()
    bp.dilate()
    bp.erode()
    mask_imp = ImagePlus("Mask", bp)
    IJ.run(mask_imp, "Create Selection", "")
    roi = mask_imp.getRoi()
    rimp.setRoi(roi)
    mean_r = rimp.getStatistics().mean
    rimp.close()
    mask_imp.close()
    return mean_r