def get_edges(a, convex=False):
a = checkma(a)
#Need to deal with RGB images here
#Need to be careful, probably want to take minimum value from masks
if a.ndim == 3:
#Assume that the same mask applies to each band
#Only create edges for one band
b = a[:,:,0]
#Could convert to HSL and do edges for L channel
#b = a[:,:,0].mask + a[:,:,1].mask + a[:,:,2].mask
else:
b = a
#Compute edges along both axes, need both to handle undercuts
#These are inclusive, indices indicate position of unmasked data
edges0 = np.ma.notmasked_edges(b, axis=0)
edges1 = np.ma.notmasked_edges(b, axis=1)
edges = np.array([np.concatenate([edges0[0][0], edges0[1][0], edges1[1][0], edges1[0][0]]), np.concatenate([edges0[0][1], edges0[1][1], edges1[1][1], edges1[0][1]])])
#This is a rough outline - needs testing
if convex:
from scipy.spatial import ConvexHull
#hull = ConvexHull(edges.T)
#edges = edges.T[hull.simplices]
#This is in scipy v0.14
#edges0 = edges1 = hull.vertices
return edges0, edges1, edges
评论列表
文章目录