def staffline_surroundings_mask(staffline_cropobject):
"""Find the parts of the staffline's bounding box which lie
above or below the actual staffline.
These areas will be very small for straight stafflines,
but might be considerable when staffline curvature grows.
"""
# We segment both masks into "above staffline" and "below staffline"
# areas.
elevation = staffline_cropobject.mask * 255
# Blur, to plug small holes somewhat:
elevation = gaussian(elevation, sigma=1.0)
# Prepare the segmentation markers: 1 is ABOVE, 2 is BELOW
markers = numpy.zeros(staffline_cropobject.mask.shape)
markers[0, :] = 1
markers[-1, :] = 2
markers[staffline_cropobject.mask != 0] = 0
seg = watershed(elevation, markers)
bmask = numpy.ones(seg.shape)
bmask[seg != 2] = 0
tmask = numpy.ones(seg.shape)
tmask[seg != 1] = 0
return bmask, tmask
##############################################################################
评论列表
文章目录