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 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, )]
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, )]
Example #4
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__)
Example #5
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 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__)
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 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 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 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 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 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__)