def error_center_line(self, image, npoints = all, order = 1, overlap = True):
"""Error between worm center line and image
Arguments:
image (array): gray scale image of worm
"""
import shapely.geometry as geo
if overlap:
xyl, xyr, cl = self.sides(npoints = npoints);
w = np.ones(npoints);
#plt.figure(141); plt.clf();
worm = geo.Polygon();
for i in range(npoints-1):
poly = geo.Polygon(np.array([xyl[i,:], xyr[i,:], xyr[i+1,:], xyl[i+1,:]]));
ovl = worm.intersection(poly).area;
tot = poly.area;
w[i+1] = 1 - ovl / tot;
worm = worm.union(poly);
#print w
return np.sum(w * nd.map_coordinates(image.T, cl.T, order = order))
else:
cl = self.center_line(npoints = npoints);
return np.sum(nd.map_coordinates(image.T, cl.T, order = order))
评论列表
文章目录