class lyric_height_estimation(PluginFunction):
    """
    Returns the estimation of average lyric height.

    *baseline*
        local minimum vertex map of lyric baseline.

    *staffspace*
        staffspace height.

    *scalar_cc_strip*
        it should be the same as the parameter used in baseline_detection.

    *scalar_height*
        scala_valid_height*staffspace: maximum height of potential lyric.
    """
    return_type = Real("output")
    self_type = ImageType([ONEBIT])
    args = Args([ImageType([ONEBIT], "baseline"),
                 Real("staffspace"),
                 Real("scalar_cc_strip", default=1.0),
                 Real("scalar_height", default=3.0)])

    def __call__(self, baseline, staffspace,
                 scalar_cc_strip=1.0, scalar_height=3.0):
        return _lyricline.lyric_height_estimation(self, baseline, staffspace,
                                             scalar_cc_strip, scalar_height)
    __call__ = staticmethod(__call__)
class mask_fill(PluginFunction):
    """
    fills masked region with color
  """
    return_type = ImageType([GREYSCALE, ONEBIT], "output")
    self_type = ImageType([GREYSCALE, ONEBIT])
    args = Args([ImageType([ONEBIT], "mask"), Int("color")])

    def __call__(self, mask, color):
        return _background_estimation.mask_fill(self, mask, color)

    __call__ = staticmethod(__call__)
Пример #3
0
class edge_detection(PluginFunction):
    """
    Detects and combines edges from two images in different levels of smoothness.

    *image2*
        the image of same subject as current image, but in lower level of smoothness.
        (the result of "paper_estimation" with sign=0)

    *threshold1_scale*
        scale for canny edge detector on current image. See Edge->canny_edge_image for details.

    *threshold1_gradient*
        gradient for canny edge detector on current image. See Edge->canny_edge_image for details.

    *threshold2_scale*
        scale for canny edge detector on image2. See Edge->canny_edge_image for details.

    *threshold2_gradient*
        gradient for canny edge detector on image2. See Edge->canny_edge_image for details.

    *transfer_para*
        edge tranfer parameter.
        Ther higher it is, the more edges in image2 will be combined into final edge map.
    """
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([
        ImageType([GREYSCALE], "image2"),
        Real("threshold1_scale", default=0.8),
        Real("threshold1_gradient", default=6.0),
        Real("threshold2_scale", default=0.8),
        Real("threshold2_gradient", default=6.0),
        Real("tranfer_parameter", default=0.25)
    ])

    def __call__(self,
                 image2,
                 threshold1_scale,
                 threshold1_gradient,
                 threshold2_scale,
                 threshold2_gradient,
                 scale_length=0.25):
        return _border_removal.edge_detection(self, image2, threshold1_scale,
                                              threshold1_gradient,
                                              threshold2_scale,
                                              threshold2_gradient,
                                              scale_length)

    __call__ = staticmethod(__call__)
Пример #4
0
class border_removal(PluginFunction):
    """
    Returns the mask of music score region.

    Gathers paper_estimation, edge_detection and boundary_reconstruct functions.
    """
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([
        Int("win_dil", default=3),
        Int("win_avg", default=5),
        Int("win_med", default=5),
        Real("threshold1_scale", default=0.8),
        Real("threshold1_gradient", default=6.0),
        Real("threshold2_scale", default=0.8),
        Real("threshold2_gradient", default=6.0),
        Real("transfer_parameter", default=0.25),
        Int("terminate_time1", default=15),
        Int("terminate_time2", default=23),
        Int("terminate_time3", default=75),
        Int("interval2", default=45),
        Int("interval3", default=15)
    ])

    def __call__(self,
                 win_dil=3,
                 win_avg=5,
                 win_med=5,
                 threshold1_scale=0.8,
                 threshold1_gradient=6.0,
                 threshold2_scale=0.8,
                 threshold2_gradient=6.0,
                 transfer_parameter=0.25,
                 terminate_time1=15,
                 terminate_time2=23,
                 terminate_time3=75,
                 interval2=45,
                 interval3=15):
        return _border_removal.border_removal(
            self, win_dil, win_avg, win_med, threshold1_scale,
            threshold1_gradient, threshold2_scale, threshold2_gradient,
            transfer_parameter, terminate_time1, terminate_time2,
            terminate_time3, interval2, interval3)

    __call__ = staticmethod(__call__)
class equalise_histogram_mask(PluginFunction):
    """
     Normalises the histogram of the given image to match an input
     histogram within mask region
  """
    return_type = ImageType([GREYSCALE], "output")
    self_type = ImageType([GREYSCALE])
    args = Args(
        [ImageType([ONEBIT], "mask"),
         FloatVector("reference_histogram")])

    def __call__(self, mask, reference_histogram):
        return _background_estimation.equalise_histogram_mask(
            self, mask, reference_histogram)

    __call__ = staticmethod(__call__)
class staffheight_estimation(PluginFunction):
    """
    Returns the staffline height of music score.

    *staff_win*
        width of each vertical strip. Local projection is done within each strip.

    *staffspace_threshold1*, *staffspace_threshold2*
        staffspace_threshold1 is the minimum height of staffline height. If the estimation is underneath this threshold,
        chose the next peak whose staffspace is over staffspace_threshold2
    """
    return_type = Int("output")
    self_type = ImageType([ONEBIT])
    args = Args([
        Int("staff_win", default=30),
        Int("staffspace_threshold1", default=5),
        Int("staffspace_threshold2", default=10)
    ])

    def __call__(self,
                 staff_win=30,
                 staffspace_threshold1=5,
                 staffspace_threshold2=10):
        return _staff_removal.staffheight_estimation(self, staff_win,
                                                     staffspace_threshold1,
                                                     staffspace_threshold2)

    __call__ = staticmethod(__call__)
class background_estimation(PluginFunction):
    """
    background estimation

    *med_size*
        the kernel for median filter.
        the default value works best for image with size 1000*1000 to 2000*2000
    """
    return_type = ImageType([GREYSCALE], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([Int("med_size", default=17)])

    def __call__(self, med_size=17):
        return _background_estimation.background_estimation(self, med_size)

    __call__ = staticmethod(__call__)
class gatos_threshold_mask(PluginFunction):
    """
    Thresholds an image according to Gatos et al.'s method. See:

    Gatos, Basilios, Ioannis Pratikakis, and Stavros
    J. Perantonis. 2004. An adaptive binarization technique for low
    quality historical documents. *Lecture Notes in Computer
    Science* 3163: 102-113.

    This version adds masking process. Only regions within the mask are binarized, the rest is filled with white color

    *background*
      Estimated background of the image.

    *binarization*
      A preliminary binarization of the image.

    *mask*
      Mask image that defines the process region

    Use the default settings for the other parameters unless you know
    what you are doing.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([
        ImageType([GREYSCALE], "background"),
        ImageType([ONEBIT], "binarization"),
        ImageType([ONEBIT], "mask"),
        Real("q", default=0.6),
        Real("p1", default=0.5),
        Real("p2", default=0.8)
    ])

    def __call__(self, background, binarization, mask, q=0.6, p1=0.5, p2=0.8):
        return _background_estimation.gatos_threshold_mask(self, \
                                            background, \
                                            binarization, \
                                            mask, \
                                            q, \
                                            p1, \
                                            p2)

    __call__ = staticmethod(__call__)
Пример #9
0
class boundary_reconstruct(PluginFunction):
    """
    Reconstructs boundary of music score based on edge map from edg_detection.

    *terminate_time1*
        maximum numbers of iterations in 1st round.

    *terminate_time2*
        maximum numbers of iterations in 2nd round.

    *terminate_time3*
        maximum numbers of iterations in 3rd round.

    *interval2*
        interval for edge adding in 2nd round.

    *interval3*
        interval for edge adding in 3rd round.
    """
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([
        Int("terminate_time1", default=15),
        Int("terminate_time2", default=23),
        Int("terminate_time3", default=75),
        Int("interval2", default=45),
        Int("interval3", default=15)
    ])

    def __call__(self,
                 terminate_time1=15,
                 terminate_time2=23,
                 terminate_time3=75,
                 interval2=45,
                 interval3=15):
        return _border_removal.boundary_reconstruct(self, terminate_time1,
                                                    terminate_time2,
                                                    terminate_time3, interval2,
                                                    interval3)

    __call__ = staticmethod(__call__)
class lyric_line_detection(PluginFunction):
    """
    Returns the mask of lyric lines.

    Gathers baseline_detection, lyric_height_estimation and lyric_line_fit functions.

    Note: no post-processing to extract precise posistion of each lyric or deal with overlapping situation is applied.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([Real("staffspace"),
                 Int("threshold_noise", default=15),
                 Real("scalar_cc_strip", default=1.0),
                 Real("seg_angle_degree", default=30.0),
                 Real("scalar_seg_dist", default=3.5),
                 Int("min_group", default=4),
                 Real("merge_angle_degree", default=5.0),
                 Real("scalar_merge_dist", default=5.0),
                 Real("valid_angle_degree", default=20.0),
                 Real("scalar_valid_height", default=1.0),
                 Int("valid_min_group", default=8),
                 Real("scalar_height", default=3.0),
                 Real("fit_angle_degree", default=2.5),
                 Real("scalar_search_height", default=1.2),
                 Real("scalar_fit_up", default=1.2),
                 Real("scalar_fit_down", default=0.3)])

    def __call__(self, staffspace,
                 threshold_noise=15, scalar_cc_strip=1.0,
                 seg_angle_degree=30.0, scalar_seg_dist=3.5, min_group=4,
                 merge_angle_degree=5.0, scalar_merge_dist=5.0,
                 valid_angle_degree=20.0, scalar_valid_height=1.0, valid_min_group=8,
                 scalar_height=3.0,
                 fit_angle_degree=2.5, scalar_search_height=1.2,
                 scalar_fit_up=1.2, scalar_fit_down=0.3):
        return _lyricline.lyric_line_detection(self, staffspace,
                                             threshold_noise, scalar_cc_strip,
                                             seg_angle_degree, scalar_seg_dist, min_group,
                                             merge_angle_degree, scalar_merge_dist,
                                             valid_angle_degree, scalar_valid_height, valid_min_group,
                                             scalar_height,
                                             fit_angle_degree, scalar_search_height,
                                            scalar_fit_up, scalar_fit_down)
    __call__ = staticmethod(__call__)
class count_black_under_line_points(PluginFunction):
    """
    Returns the number of pixels beneath a given line that are the given colour.
    The arguments x0, y0 are the start coordinates of the line and the arguments
    x1, y1 are the end coordinates of the line.
    """
    self_type = ImageType([ONEBIT])
    return_type = Int("num_black_pixels")
    args = Args([Real("x0"), Real("y0"), Real("x1"), Real("y1")])
    doc_examples = [(ONEBIT, )]
Пример #12
0
class med_filter(PluginFunction):
    """
    Returns the regional intermediate value of an image as a FLOAT.

    *region_size*
      The size of the region within which to calculate the intermediate pixel value.
    """
    return_type = ImageType([FLOAT], "output")
    self_type = ImageType([GREYSCALE, GREY16, FLOAT])
    args = Args([Int("region size", default=5)])
    doc_examples = [(GREYSCALE, ), (GREY16, ), (FLOAT, )]
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"

    def __call__(self, region_size=5):
        return _border_removal.med_filter(self, region_size)

    __call__ = staticmethod(__call__)
class count_black_under_line(PluginFunction):
    """
    Returns the number of pixels beneath a given line that are black.
    The arguments 'slope' and 'y_intercept' correspond to the m and b in the
    equation of a line, y = m * x + b, respectively. I don't know if this works
    properly because I've had it count white pixels as black ones...
    """
    self_type = ImageType([ONEBIT])
    return_type = Int("num_black_pixels")
    args = Args([Real("slope"), Real("y_intercept")])
    doc_examples = [(ONEBIT, )]
Пример #14
0
class flood_fill_bw(PluginFunction):
    """
    Flood fill on binary image.

    It is different from filling holes in the way generating marker and mask images.

    Algorithm reference: Luc Vincent, "Morphological Grayscale Reconstruction
    In Image Analysis: Applications and Efficient Algorithms", IEEE Transactions
    on Image Processing, vol.2, no.2, April 1993, pp. 176-201
    """
    self_type = ImageType([ONEBIT])
    return_type = ImageType([ONEBIT], "output")
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"

    def __call__(self):
        return _border_removal.flood_fill_bw(self)

    __call__ = staticmethod(__call__)
Пример #15
0
class flood_fill_holes_grey(PluginFunction):
    """
    Fills holes in an image by flood fill.

    Algorithm reference: Luc Vincent, "Morphological Grayscale Reconstruction
    In Image Analysis: Applications and Efficient Algorithms", IEEE Transactions
    on Image Processing, vol.2, no.2, April 1993, pp. 176-201

    Note: this function only works on greyscale image.
    """
    self_type = ImageType([GREYSCALE])
    return_type = ImageType([GREYSCALE], "output")
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"

    def __call__(self):
        return _border_removal.flood_fill_holes_grey(self)

    __call__ = staticmethod(__call__)
class directional_med_filter_bw(PluginFunction):
    """
    Returns the regional intermediate value of an image as a FLOAT.
    The shape of window is not necessarily a square.
    This function currently only works on binary image.

    *region_width*, *region_height*
      The size of the region within which to calculate the intermediate pixel value.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args(
        [Int("region_width", default=5),
         Int("region_height", default=5)])

    def __call__(self, region_width=5, region_height=5):
        return _staff_removal.directional_med_filter_bw(
            self, region_width, region_height)

    __call__ = staticmethod(__call__)
class lyric_line_fit(PluginFunction):
    """
    Returns the mask of lyric lines.
    The lines are estimated by linear least square fitting from local minimum vertex map of lyric baseline.

    *baseline*
        local minimum vertex map of lyric baseline.

    *lyric_height*
        estimation of average lyric height.

    *fit_angle_degree*
        tolerance on angle between lyric line and horizon(in degree).

    *scalar_search_height*
        scala_search_height*lyric_height: tolerance on distance (in y-axis) between local minimum vertices that belong to a single lyric line.

    *scalar_fit_up*
        scalar_fit_up*lyric_height: height of lyric portion above baseline.

    *scalar_fit_down*
        scalar_fit_down*lyric_height: height of lyric portion beneath baseline.

    Note: no post-processing to extract precise posistion of each lyric or deal with overlapping situation is applied.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([ImageType([ONEBIT], "baseline"),
                 Real("lyric_height"),
                 Real("fit_angle_degree", default=2.5),
                 Real("scalar_search_height", default=1.2),
                 Real("scalar_fit_up", default=1.2),
                 Real("scalar_fit_down", default=0.3)])

    def __call__(self, baseline, lyric_height,
                 fit_angle_degree=2.5, scalar_search_height=1.2,
                 scalar_fit_up=1.2, scalar_fit_down=0.3):
        return _lyricline.lyric_line_fit(self, baseline, lyric_height,
                                            fit_angle_degree, scalar_search_height,
                                            scalar_fit_up, scalar_fit_down)
    __call__ = staticmethod(__call__)
class histogram_mask(PluginFunction):
    """
    Compute the histogram of the pixel values within the mask.
    Returns a Python array of doubles, with each value being a
    percentage.

    If the GUI is being used, the histogram is displayed.

    .. image:: images/histogram.png
    """
    self_type = ImageType([GREYSCALE, GREY16])
    return_type = FloatVector()
    args = Args([ImageType([ONEBIT], "mask")])
    doc_examples = [(GREYSCALE)]

    def __call__(image, mask):
        hist = _background_estimation.histogram_mask(image, mask)
        if has_gui.has_gui == has_gui.WX_GUI:
            has_gui.gui.ShowHistogram(hist, mark=image.otsu_find_threshold())
        return hist

    __call__ = staticmethod(__call__)
class optimal_histogram(PluginFunction):
    """
    returns an optimal histogram template for binarization
    """
    pure_python = 1
    self_type = ImageType([GREYSCALE, GREY16])
    return_type = FloatVector()
    doc_examples = [(GREYSCALE)]

    def __call__(image):
        return sample_hist

    __call__ = staticmethod(__call__)
Пример #20
0
class paper_estimation(PluginFunction):
    """
    Returns the estimation of background paper by removing foreground pen strokes.

    Note: the default parameter works on image with standard area 114000 (rows*cols)

    Main process: filling hols -> mean filter -> median filter

    *sign*
        An extra smoothing process(dilation+erosion) is applied at the begining, when sign=1.
        An extra edge-preserving process(filling holes) is applied at the end, when sign=0.

    *dil_win*
        region size for dilation+erosion.

    *avg_win*
        region size for mean filter.

    *med_win*
        region size for median filter.
    """
    category = "Border Removal"
    author = "Yue Phyllis Ouyang and John Ashley Burgoyne"
    url = "http://ddmal.music.mcgill.ca/"
    return_type = ImageType([GREYSCALE], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([
        Int("sign", default=1),
        Int("dil_win", default=3),
        Int("avg_win", default=5),
        Int("med_win", default=5)
    ])

    def __call__(self, sign=1, win_dil=3, win_avg=5, win_med=5):
        return _border_removal.paper_estimation(self, sign, win_dil, win_avg,
                                                win_med)

    __call__ = staticmethod(__call__)
class wiener2_filter(PluginFunction):
    """
    Adaptive directional filtering

    *region_width*, *region_height*
      The size of the region within which to calculate the intermediate pixel value.

    *noise_variancee*
      noise variance. If negative, estimated automatically.
    """
    return_type = ImageType([GREYSCALE, GREY16, FLOAT], "output")
    self_type = ImageType([GREYSCALE, GREY16, FLOAT])
    args = Args([
        Int("region_width", default=5),
        Int("region_height", default=5),
        Real("noise_variance", default=-1.0)
    ])

    def __call__(self, region_width=5, region_height=5, noise_variance=-1.0):
        return _background_estimation.wiener2_filter(self, region_width,
                                                     region_height,
                                                     noise_variance)

    __call__ = staticmethod(__call__)
class find_blackest_lines(PluginFunction):
    """
    Operates on a binarised image and a list of its horizontal projections. Finds
    local peaks in the horizontal projections of the image. This means it adds up
    the number of times black is seen in a row and stores the value for each row
    in an array. It then finds local peaks in this array. It then draws a bunch of
    lines on the image, all pivoting around the centres of the horizontal
    projections. It discards all but the lines that cross the most black pixels
    and returns the start and end points of these lines, e.g.
    [ [(x00,y00),(x01,y01)], [(x10,y10),(x11,y11)], ... [(xn0,yn0),(xn1,yn1)] ].

    Parameters:

      minimum_y_threshold: the minimum value that may be considered a local peak
      in the horizontal projection.

      num_searches: the number of searches to do around each local peak

      negative_bound: how far below the local peak to start the line search (this
      value is positive! so the value of negative_bound=10 will start searching 10
      pixels below the peak-point (or -10 pixels. To make this even more
      confusing, the negative direction is actually upward when talking about
      images, but you already knew this from reading the Gamera documentation).

      positive_bound: how far above the local peak to start the line search

      delta: see the delta parameter for the peakdet function above

      thickness_above: the number of parallel lines to add above the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines

      thickness_below: the number of parallel lines to add below the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines
    """
    self_type = ImageType([ONEBIT])
    args = Args([
        Class('horizontal_projections', list),
        Int("minimum_y_threshold"),
        Int("num_searches"),
        Int("negative_bound"),
        Int("positive_bound"),
        Int("delta"),
        Int("thickness_above"),
        Int("thickness_below")
    ])
    return_type = Float("area")
    pure_python = True

    @staticmethod
    def __call__(self,
                 horizontal_projections,
                 minimum_y_threshold,
                 num_searches,
                 negative_bound,
                 positive_bound,
                 delta=10,
                 thickness_above=0,
                 thickness_below=0):
        return lyric_extractor_helper._find_blackest_lines(
            self, horizontal_projections, minimum_y_threshold, num_searches,
            negative_bound, positive_bound, delta, thickness_above,
            thickness_below)
class binarization(PluginFunction):
    """

    *mask*
      Mask image that defines the process region

    *do_wiener*
      1 if adding wiener filtering before binarization, otherwise 0

    *region_width*, *region_height*, *noise_variance*
      parameters for wiener filter

    *med_size*
      The kernel for median filter.

    *region size*, *sensitivity*, *dynamic range*, *lower bound*, *upper bound*
      parameters for sauvola binarization

    *q*, *p1*, *p2*
      parameters for gatos thresholding

    the default values for wiener and median filtrs works best for image with size 1000*1000 to 2000*2000
    Use the default settings for the other parameters unless you know
    what you are doing.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([GREYSCALE])
    args = Args([
        ImageType([ONEBIT], "mask"),
        FloatVector("reference_histogram"),
        Int("do_wiener", default=0),
        Int("wiener_width", default=5),
        Int("wiener_height", default=3),
        Real("noise_variance", default=-1.0),
        Int("med_size", default=17),
        Int("region size", default=15),
        Real("sensitivity", default=0.5),
        Int("dynamic range", range=(1, 255), default=128),
        Int("lower bound", range=(0, 255), default=20),
        Int("upper bound", range=(0, 255), default=150),
        Real("q", default=0.06),
        Real("p1", default=0.7),
        Real("p2", default=0.5)
    ])

    def __call__(self,
                 mask,
                 reference_histogram,
                 do_wiener=0,
                 wiener_width=5,
                 wiener_height=3,
                 noise_variance=-1.0,
                 med_size=17,
                 region_size=15,
                 sensitivity=0.5,
                 dynamic_range=128,
                 lower_bound=20,
                 upper_bound=150,
                 q=0.06,
                 p1=0.7,
                 p2=0.5):
        return _background_estimation.binarization(
            self, mask, reference_histogram, do_wiener, wiener_width,
            wiener_height, noise_variance, med_size, region_size, sensitivity,
            dynamic_range, lower_bound, upper_bound, q, p1, p2)

    __call__ = staticmethod(__call__)
class baseline_detection(PluginFunction):
    """
    Detects the baseline of lyrics.
    Returns the local minimum vertex map of lyric baseline.

    *staffspace*
        staffspace height.

    *thershold noise*
        minimum area of connected component not considered as noise.

    *scalar_cc_strip*
        long connected components are broked into strips with certain width, scalar_cc_strip*staffspace.

    *seg_angle_degree*
        tolerance on angle between two adjacent local minimum vertices of the same line (in degree).

    *scalar_seg_dist*
        scalar_seg_dist*staffspace: tolerance on distance (in x-axis) between two adjacent local minimum vertices of the same line.

    *min_group*
        minimun number of local minimum vertices in a potential baseline segment.

    *merge_angle_degree*
        tolerance on angle between two adjacent potential baseline segments to merge into one line (in degree).

    *scalar_merge_dist*
        scalar_merge_dist*staffspace: tolerance on distance (in x-axis) between two adjacent potential baseline segments to merge into one line.

    *valid_angle_degree*
        tolerance on angle between baseline and horizon(in degree).

    *scalar_valid_height*
        scala_valid_height*staffspace: tolerance on distance (in y-axis) between local minimum vertices and the estimated baseline they belong to.

    *valid_min_group*
        minimun number of local minimum vertices in a baseline.
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([Real("staffspace"),
                 Int("threshold_noise", default=15),
                 Real("scalar_cc_strip", default=1.0),
                 Real("seg_angle_degree", default=30.0),
                 Real("scalar_seg_dist", default=3.5),
                 Int("min_group", default=4),
                 Real("merge_angle_degree", default=5.0),
                 Real("scalar_merge_dist", default=5.0),
                 Real("valid_angle_degree", default=20.0),
                 Real("scalar_valid_height", default=1.0),
                 Int("valid_min_group", default=8)])

    def __call__(self, staffspace,
                 threshold_noise=15, scalar_cc_strip=1.0,
                 seg_angle_degree=30.0, scalar_seg_dist=3.5, min_group=4,
                 merge_angle_degree=5.0, scalar_merge_dist=5.0,
                 valid_angle_degree=30.0, scalar_valid_height=1.0, valid_min_group=8):
        return _lyricline.baseline_detection(self, staffspace,
                                             threshold_noise, scalar_cc_strip,
                                             seg_angle_degree, scalar_seg_dist, min_group,
                                             merge_angle_degree, scalar_merge_dist,
                                             valid_angle_degree, scalar_valid_height, valid_min_group)
    __call__ = staticmethod(__call__)
class extract_lyrics(PluginFunction):
    """
    Takes in a binarised image and attempts to remove lyrics by processing horizontal
    projections (see find_blackest_lines).  Whatever lines are found from find_blackest_lines
    are superimposed onto the connected components of the image.  Those CCs are then removed
    from the binarised image.

    Parameters:

      minimum_y_threshold: the minimum value that may be considered a local peak
      in the horizontal projection.

      num_searches: the number of searches to do around each local peak

      negative_bound: how far below the local peak to start the line search (this
      value is positive! so the value of negative_bound=10 will start searching 10
      pixels below the peak-point (or -10 pixels. To make this even more
      confusing, the negative direction is actually upward when talking about
      images, but you already knew this from reading the Gamera documentation).

      positive_bound: how far above the local peak to start the line search

      thickness_above: the number of parallel lines to add above the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines

      thickness_below: the number of parallel lines to add below the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines
    """
    pure_python = 1
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([
        Int("minimum_y_threshold", default=10),
        Int("num_searches", default=4),
        Int("negative_bound", default=10),
        Int("postive_bound", default=10),
        Int("thickness_above", default=0),
        Int("thickness_below", default=0)
    ])

    def __call__(self,
                 minimum_y_threshold=10,
                 num_searches=4,
                 negative_bound=10,
                 postive_bound=10,
                 thickness_above=0,
                 thickness_below=0):
        result = lyric_extractor_helper.extract_lyric_ccs(
            self,
            minimum_y_threshold=10,
            num_searches=4,
            negative_bound=10,
            postive_bound=10,
            thickness_above=0,
            thickness_below=0)
        for cc in set(result[0]) - set(result[1]):
            cc.fill_white()
        return self

    __call__ = staticmethod(__call__)
class segment_by_colour(PluginFunction):
    """
    Same as extract_lyrics, only the lyrics and neumes are highlighted by the specified colours (neums: red, text: black).

    Parameters:

      minimum_y_threshold: the minimum value that may be considered a local peak
      in the horizontal projection.

      num_searches: the number of searches to do around each local peak

      negative_bound: how far below the local peak to start the line search (this
      value is positive! so the value of negative_bound=10 will start searching 10
      pixels below the peak-point (or -10 pixels. To make this even more
      confusing, the negative direction is actually upward when talking about
      images, but you already knew this from reading the Gamera documentation).

      positive_bound: how far above the local peak to start the line search

      thickness_above: the number of parallel lines to add above the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines

      thickness_below: the number of parallel lines to add below the original 
      intercept line; this simulates "thickness" above the line; use 0 for just no 
      extra lines
    """
    pure_python = 1
    return_type = ImageType([RGB], "output")
    self_type = ImageType([ONEBIT])
    args = Args([
        Int("minimum_y_threshold", default=10),
        Int("num_searches", default=4),
        Int("negative_bound", default=10),
        Int("postive_bound", default=10),
        Int("thickness_above", default=0),
        Int("thickness_below", default=0)
    ])

    def __call__(self,
                 minimum_y_threshold=10,
                 num_searches=4,
                 negative_bound=10,
                 postive_bound=10,
                 thickness_above=0,
                 thickness_below=0):
        from gamera.core import RGBPixel

        # Do analysis.
        result = lyric_extractor_helper.extract_lyric_ccs(
            self, minimum_y_threshold, num_searches, negative_bound,
            postive_bound, thickness_above, thickness_below)

        # Check color input.
        neumeColour = RGBPixel(0, 255, 0)
        lyricColour = RGBPixel(255, 0, 0)

        # Prepare output image.
        returnImage = self.to_rgb()

        # Do highlighting.
        for cc in set(result[0]) - set(result[1]):
            returnImage.highlight(cc, lyricColour)
        for cc in set(result[1]):
            returnImage.highlight(cc, neumeColour)
        return returnImage

    __call__ = staticmethod(__call__)
class staff_removal(PluginFunction):
    """
    Removes stafflines from music scores.
    Note: it is specially for lyric line detection and cannot be used directly for standard staff removal.

    Main process: directional median filter -> reconsider pixels in neighbourhood of potential non-staff pixels

    *staffspace*
        staffspace height. If negative, estimated automatically.

    *staffheight*
        staff height. If negative, estimated automatically.

    *scalar_med_width_staffspace*, *scalar_med_height_staffspace*
        (scalar_med_width_staffspace*staffspace, scalar_med_height_staffspace*staffspace):
        region size for median filter estimated from staffspace.

    *scalar_med_width_staffheight*, *scalar_med_height_staffheight*
        (scalar_med_width_staffheight*staffheight, scalar_med_height_staffheight*staffheight):
        region size for median filter estimated from staffheight.

    *neighbour_width*, *neighbour_height*
        region size defined as neighbourhood of a pixel.

    *staff_win*
        width of each vertical strip. Local projection is done within each strip.

    *staffspace_threshold1*, *staffspace_threshold2*
        staffspace_threshold1 is the minimum height of staffline height. If the estimation is underneath this threshold,
        chose the next peak whose staffspace is over staffspace_threshold2
    """
    return_type = ImageType([ONEBIT], "output")
    self_type = ImageType([ONEBIT])
    args = Args([
        Int("staffspace", default=-1),
        Int("staffheight", default=-1),
        Real("scalar_med_width_staffspace", default=0.15),
        Real("scalar_med_height_staffspace", default=0.6),
        Real("scalar_med_width_staffheight", default=1.2),
        Real("scalar_med_height_staffheight", default=5.0),
        Int("neighbour_width", default=1),
        Int("neighbour_height", default=1),
        Int("staff_win", default=30),
        Int("staffspace_threshold1", default=5),
        Int("staffspace_threshold2", default=10)
    ])

    def __call__(self,
                 staffspace=-1,
                 staffheight=-1,
                 scalar_med_width_staffspace=0.15,
                 scalar_med_height_staffspace=0.6,
                 scalar_med_width_staffheight=1.2,
                 scalar_med_height_staffheight=5.0,
                 neighbour_width=1,
                 neighbour_height=1,
                 staff_win=30,
                 staffspace_threshold1=5,
                 staffspace_threshold2=10):
        return _staff_removal.staff_removal(
            self, staffspace, staffheight, scalar_med_width_staffspace,
            scalar_med_height_staffspace, scalar_med_width_staffheight,
            scalar_med_height_staffheight, neighbour_width, neighbour_height,
            staff_win, staffspace_threshold1, staffspace_threshold2)

    __call__ = staticmethod(__call__)