def bleb_area(membrane_edge, midpoint_anchor):
    """calculate the area of the drawn bleb, accounting for membrane crossing line joining anchors"""
    poly = membrane_edge.getFloatPolygon()
    xs = [x for x in poly.xpoints]
    ys = [y for y in poly.ypoints]
    rotangle = membrane_edge.getAngle(int(round(xs[0])), int(round(
        ys[0])), int(round(xs[-1])), int(round(ys[-1]))) / 180 * math.pi
    rotY = [(x * math.sin(rotangle) + y * math.cos(rotangle))
            for x, y in zip(xs, ys)]
    rotYmpa = midpoint_anchor[0] * math.sin(
        rotangle) + midpoint_anchor[1] * math.cos(rotangle)
    meanRotY = sum(rotY) / len(rotY)
    seg1 = rotY[:int(round(len(rotY) / 2))]
    seg1.reverse()
    seg2 = rotY[int(round(len(rotY) / 2)):]
    if rotYmpa > rotY[0]:
        idx1 = len(seg1) - seg1.index(min(seg1))
        idx2 = int(round(len(rotY) / 2)) + seg2.index(min(seg2))
    else:
        idx1 = len(seg1) - seg1.index(max(seg1))
        idx2 = int(round(len(rotY) / 2)) + seg2.index(max(seg2))
    area_poly_xs = xs[idx1:idx2 + 1]
    area_poly_ys = ys[idx1:idx2 + 1]
    len_roi = PolygonRoi(area_poly_xs, area_poly_ys, Roi.POLYLINE)
    length = len_roi.getLength()
    area_roi = PolygonRoi(area_poly_xs, area_poly_ys, Roi.POLYGON)
    area = area_roi.getStatistics().area
    #print(area);
    return length, area, area_roi
Exemplo n.º 2
0
def generate_cell_shape_results(rois,
                                intensity_channel_imp,
                                cal,
                                file_name,
                                no_nuclei_centroids=None,
                                no_enclosed_nuclei=None):
    """from list of rois, generate results describing the cell enclosed in each roi"""
    pixel_width = 1.0 if cal is None else cal.pixelWidth
    if no_nuclei_centroids is None:
        no_nuclei_centroids = [0 for _ in rois]
    if no_enclosed_nuclei is None:
        no_enclosed_nuclei = [0 for _ in rois]
    cell_shapes = []
    for idx, roi in enumerate(rois):
        intensity_channel_imp.setRoi(roi)
        stats = roi.getStatistics()
        I_mean = stats.mean
        I_sd = stats.stdDev
        area = stats.area * (pixel_width**2)
        perimeter = roi.getLength()
        aspect_ratio = stats.major / stats.minor
        cvh_poly = roi.getConvexHull()
        if cvh_poly is not None:
            convex_hull_roi = PolygonRoi([x for x in cvh_poly.xpoints],
                                         [y for y in cvh_poly.ypoints],
                                         PolygonRoi.POLYGON)
        else:
            continue
        print("roi length = {}".format(roi.getLength()))
        print("convex hull roi length = {}".format(
            convex_hull_roi.getLength()))
        cell_spikiness_index = roi.getLength() / (pixel_width *
                                                  convex_hull_roi.getLength())
        cell_shapes.append(
            CellShapeResults(
                file_name=file_name,
                cell_index=idx + 1,
                cell_area_um2=area,
                cell_perimeter_um=perimeter,
                cell_aspect_ratio=aspect_ratio,
                cell_spikiness_index=cell_spikiness_index,
                cell_gfp_I_mean=I_mean,
                cell_gfp_I_sd=I_sd,
                nuclear_centroids_in_cell=no_nuclei_centroids[idx],
                nuclei_enclosed_in_cell=no_enclosed_nuclei[idx],
                roi=roi))
    return cell_shapes