def djvu_binarise(image_filepath, **kwargs): """ *smoothness* The amount of effect that parent blocks have on their children blocks. Higher values will result in more smoothness between blocks. Expressed as a percentage between 0.0 and 1.0. *max_block_size* The size of the largest block to determine a threshold. *min_block_size* The size of the smallest block to determine a threshold. *block_factor* The number of child blocks (in each direction) per parent block. For instance, a *block_factor* of 2 results in 4 children per parent. """ input_image = load_image_for_job(image_filepath, gamera.plugins.threshold.djvu_threshold) output_image = input_image.djvu_threshold( \ kwargs['smoothness'], kwargs['max_block_size'], kwargs['min_block_size'], kwargs['block_factor']) return {'tiff': output_image}
def pitch_find(xml_filepath, segmented, page_sequence, **kwargs): # Run a rank filter on the image to make the staves bigger # for pitch detection print "loading image... performing rank filter" input_image = load_image_for_job(segmented, gamera.plugins.misc_filters.rank) # XXX: Parameters to change? rank_image = input_image.rank(9, 9, 0) #gamera.core.save_image(rank_image, "aomr2-rank.tiff") print "... done. Finding pitches" try: aomr_obj = AomrObject(rank_image, \ discard_size=kwargs['discard_size'], lines_per_staff=4, staff_finder=0, staff_removal=0, binarization=0) glyphs = gamera.gamera_xml.glyphs_from_xml(xml_filepath) recognized_glyphs = aomr_obj.run(glyphs) data = json.loads(recognized_glyphs) mei_file = AomrMeiOutput(data, str(segmented), str(page_sequence)) except AomrUnableToFindStavesError as e: #if something goes wrong, this will create an empty mei file (instead of crashing) print e mei_file = AomrMeiOutput({}, str(segmented), str(page_sequence)) print "... done. Writing MEI" return { 'mei': mei_file }
def border_remover(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, gamera.toolkits.border_removal.plugins.border_removal.border_removal) mask = input_image.border_removal() # use defaults output_image = input_image.mask(mask) return { "tiff": output_image }
def find_staves(image_filepath, **kwargs): """ *num_lines*: Number of lines within one staff. When zero, the number is automatically detected. *scan_lines*: Number of vertical scan lines for extracting candidate points. *blackness*: Required blackness on the connection line between two candidate points in order to consider them matching. *tolerance*: How much the vertical black runlength of a candidate point may deviate from staffline_height. When negative, this value is set to *max([2, staffline_height / 4])*. """ # Perform a Rank filter to make the stafflines thicker input_image = load_image_for_job(image_filepath, gamera.plugins.misc_filters.rank) rank_image = input_image.rank(9, 9, 0) #both 0's can be parameterized, first one is staffline_height and second is staffspace_height, both default 0 #the constructor converts to onebit if its not ONEBIT. Note that it will simply convert, no binarisation process staff_finder = gamera.toolkits.musicstaves.StaffFinder_miyao( rank_image, 0, 0) staff_finder.find_staves(kwargs['num_lines'], kwargs['scanlines'], kwargs['blackness'], kwargs['tolerance']) poly_list = staff_finder.get_polygon() poly_list = fix_poly_point_list(poly_list, staff_finder.staffspace_height) poly_json_list = create_polygon_outer_points_json_dict(poly_list) stafffind_json_list = create_json_from_poly_list(poly_list) encoded1 = json.dumps(poly_json_list) encoded2 = json.dumps(stafffind_json_list) return { 'json': encoded1, 'json2': encoded2, }
def rank_filter(image_filepath, **kwargs): """ *rank_val* (1, 2, ..., *k* * *k*) The rank of the windows pixels to select for the center. (k*k+1)/2 is equivalent to the median. *k* (3, 5 ,7, ...) The window size (must be odd). *border_treatment* (0, 1) When 0 ('padwhite'), window pixels outside the image are set to white. When 1 ('reflect'), reflecting boundary conditions are used. """ input_image = load_image_for_job(image_filepath, gamera.plugins.misc_filters.rank) output_image = input_image.rank( \ kwargs['rank_val'], kwargs['k'], kwargs['border_treatment']) return {'tiff': output_image}
def rank_filter(image_filepath, **kwargs): """ *rank_val* (1, 2, ..., *k* * *k*) The rank of the windows pixels to select for the center. (k*k+1)/2 is equivalent to the median. *k* (3, 5 ,7, ...) The window size (must be odd). *border_treatment* (0, 1) When 0 ('padwhite'), window pixels outside the image are set to white. When 1 ('reflect'), reflecting boundary conditions are used. """ input_image = load_image_for_job(image_filepath, gamera.plugins.misc_filters.rank) output_image = input_image.rank( \ kwargs['rank_val'], kwargs['k'], kwargs['border_treatment']) return { 'tiff': output_image }
def find_staves(image_filepath, **kwargs): """ *num_lines*: Number of lines within one staff. When zero, the number is automatically detected. *scan_lines*: Number of vertical scan lines for extracting candidate points. *blackness*: Required blackness on the connection line between two candidate points in order to consider them matching. *tolerance*: How much the vertical black runlength of a candidate point may deviate from staffline_height. When negative, this value is set to *max([2, staffline_height / 4])*. """ # Perform a Rank filter to make the stafflines thicker input_image = load_image_for_job(image_filepath, gamera.plugins.misc_filters.rank) rank_image = input_image.rank(9, 9, 0) # both 0's can be parameterized, first one is staffline_height and second is staffspace_height, both default 0 # the constructor converts to onebit if its not ONEBIT. Note that it will simply convert, no binarisation process staff_finder = gamera.toolkits.musicstaves.StaffFinder_miyao(rank_image, 0, 0) staff_finder.find_staves(kwargs["num_lines"], kwargs["scanlines"], kwargs["blackness"], kwargs["tolerance"]) poly_list = staff_finder.get_polygon() poly_list = fix_poly_point_list(poly_list, staff_finder.staffspace_height) poly_json_list = create_polygon_outer_points_json_dict(poly_list) stafffind_json_list = create_json_from_poly_list(poly_list) encoded1 = json.dumps(poly_json_list) encoded2 = json.dumps(stafffind_json_list) return {"json": encoded1, "json2": encoded2}
def djvu_binarise(image_filepath, **kwargs): """ *smoothness* The amount of effect that parent blocks have on their children blocks. Higher values will result in more smoothness between blocks. Expressed as a percentage between 0.0 and 1.0. *max_block_size* The size of the largest block to determine a threshold. *min_block_size* The size of the smallest block to determine a threshold. *block_factor* The number of child blocks (in each direction) per parent block. For instance, a *block_factor* of 2 results in 4 children per parent. """ input_image = load_image_for_job(image_filepath, gamera.plugins.threshold.djvu_threshold) output_image = input_image.djvu_threshold( kwargs["smoothness"], kwargs["max_block_size"], kwargs["min_block_size"], kwargs["block_factor"] ) return {"tiff": output_image}
def auto_rotate(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, correct_rotation) output_image = input_image.correct_rotation(0) return { 'tiff': output_image }
def auto_rotate(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, correct_rotation) output_image = input_image.correct_rotation(0) return {'tiff': output_image}
def brink_binarise(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, brink_threshold) output_image = input_image.brink_threshold() return {'tiff': output_image}
def simple_binarise(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, gamera.plugins.threshold.threshold) output_image = input_image.threshold(kwargs['threshold']) return {'tiff': output_image}
def brink_binarise(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, brink_threshold) output_image = input_image.brink_threshold() return {"tiff": output_image}
def simple_binarise(image_filepath, **kwargs): input_image = load_image_for_job(image_filepath, gamera.plugins.threshold.threshold) output_image = input_image.threshold(kwargs["threshold"]) return {"tiff": output_image}