def __call__(self, im_staffonly, min, max, c=0.5, random_seed=0): from gamera.core import Image, RGBPixel from gamera.toolkits.musicstaves.stafffinder import StafflineSkeleton seed(random_seed) im_full = self im_staffless = im_full.xor_image(im_staffonly) [first_x, last_x, stafflines, thickness] = find_stafflines_int(im_staffonly) def_staffonly = Image(im_full.ul, im_full.size) # state machine for the thickness states = states_mh(max - min + 1, c) # draw the deformed stafflines in a blank image last_thickness = 0 even_shift = 0 for l in range(len(stafflines)): y = stafflines[l] for x in range(first_x, last_x + 1): thickness = states.next() + min y_st = y - thickness / 2 if thickness % 2 == 0: if thickness != last_thickness: if random() < 0.5: even_shift = 1 else: even_shift = 0 y_st = y_st + even_shift if thickness > 0: def_staffonly.draw_line((x, y_st), (x, y_st + thickness - 1), RGBPixel(255, 255, 255)) last_thickness = thickness # stafflines = stafflines AND NOT symbols im_staffless_invert = im_staffless.image_copy() im_staffless_invert.invert() def_staffonly.and_image(im_staffless_invert, True) # full = symbols OR stafflines def_full = im_staffless.image_copy() def_full.or_image(def_staffonly, True) # construct skeletons (in fact they didn't change) staffline_skel = [] for y in stafflines: skel = StafflineSkeleton() skel.left_x = first_x # all stafflines are completely straight skel.y_list = (last_x - first_x + 1) * [y] staffline_skel.append(skel) return [def_full, def_staffonly, staffline_skel]
def __call__(self,im_staffonly,min,max,c=0.5,random_seed=0): from gamera.core import Image,RGBPixel from gamera.toolkits.musicstaves.stafffinder import StafflineSkeleton seed(random_seed) im_full=self im_staffless=im_full.xor_image(im_staffonly) [first_x, last_x, stafflines, thickness]=find_stafflines_int(im_staffonly) def_staffonly=Image(im_full.ul,im_full.size) # state machine for the thickness states=states_mh(max-min+1,c) # draw the deformed stafflines in a blank image last_thickness=0 even_shift=0 for l in range(len(stafflines)): y=stafflines[l] for x in range(first_x,last_x+1): thickness=states.next()+min y_st=y-thickness/2 if thickness%2==0: if thickness!=last_thickness: if random()<0.5: even_shift=1 else: even_shift=0 y_st=y_st+even_shift if thickness>0: def_staffonly.draw_line((x,y_st),(x,y_st+thickness-1),RGBPixel(255,255,255)) last_thickness=thickness # stafflines = stafflines AND NOT symbols im_staffless_invert=im_staffless.image_copy() im_staffless_invert.invert() def_staffonly.and_image(im_staffless_invert,True) # full = symbols OR stafflines def_full=im_staffless.image_copy() def_full.or_image(def_staffonly,True) # construct skeletons (in fact they didn't change) staffline_skel=[] for y in stafflines: skel=StafflineSkeleton() skel.left_x=first_x # all stafflines are completely straight skel.y_list=(last_x-first_x+1)*[y] staffline_skel.append(skel) return [def_full,def_staffonly,staffline_skel]
def __call__(self, im_staffonly, maxdiff, c=0.5, random_seed=0): from gamera.core import Image, RGBPixel from gamera.toolkits.musicstaves.stafffinder import StafflineSkeleton seed(random_seed) im_full = self im_staffless = im_full.xor_image(im_staffonly) [first_x, last_x, stafflines, thickness] = find_stafflines_int(im_staffonly) def_staffonly = Image(im_full.ul, im_full.size) states = states_mh(2 * maxdiff + 1, c) m = (thickness - 1) / 2 if (thickness and 1) == 1: p = m else: p = m + 1 staffline_skel = [] for l in range(len(stafflines)): y = stafflines[l] - maxdiff skel = StafflineSkeleton() skel.left_x = first_x skel.y_list = (last_x - first_x + 1) * [y] for x in range(first_x, last_x + 1): y_l = y + states.next() skel.y_list[x - first_x] = y_l def_staffonly.draw_line((x, y_l - m), (x, y_l + p), RGBPixel(255, 255, 255)) staffline_skel.append(skel) im_staffless_invert = im_staffless.image_copy() im_staffless_invert.invert() def_staffonly.and_image(im_staffless_invert, True) def_staffless = im_staffless.image_copy() def_full = im_staffless.image_copy() def_full.or_image(def_staffonly, True) return [def_full, def_staffonly, staffline_skel]
def __call__(self,im_staffonly,maxdiff,c=0.5,random_seed=0): from gamera.core import Image,RGBPixel from gamera.toolkits.musicstaves.stafffinder import StafflineSkeleton seed(random_seed) im_full=self im_staffless=im_full.xor_image(im_staffonly) [first_x, last_x, stafflines, thickness]=find_stafflines_int(im_staffonly) def_staffonly=Image(im_full.ul,im_full.size) states=states_mh(2*maxdiff+1,c) m=(thickness-1)/2 if (thickness and 1)==1: p=m else: p=m+1 staffline_skel=[] for l in range(len(stafflines)): y=stafflines[l]-maxdiff skel=StafflineSkeleton() skel.left_x=first_x skel.y_list=(last_x-first_x+1)*[y] for x in range(first_x,last_x+1): y_l=y+states.next() skel.y_list[x-first_x]=y_l def_staffonly.draw_line((x,y_l-m),(x,y_l+p),RGBPixel(255,255,255)) staffline_skel.append(skel) im_staffless_invert=im_staffless.image_copy() im_staffless_invert.invert() def_staffonly.and_image(im_staffless_invert,True) def_staffless=im_staffless.image_copy() def_full=im_staffless.image_copy() def_full.or_image(def_staffonly,True) return [def_full,def_staffonly,staffline_skel]