Exemple #1
0
    def ccs_overall(self):
        """ Segment image in inside/outside staves,text,dynamics and return the
        ccs for each of these segments as a dict:
            return {
                     'all'
                     'outside'
                     'inside'
                     'text'
                     'classified'
                }
        """
        ret = {}
        if self._ccs is None:
            baseimg = self.without_staves()
            ccs = set(baseimg.cc_analysis())
            stavey = self.ms().get_staffpos()
            if stavey is None:
                raise NoStavesException,"No stafflines, no need for anything here.  Abort"
            cond = inout_staff_condition(self.ms().get_staffpos())
            ret["all"] = ccs
            ret["outside"] = [ c for c in ccs if not cond(c)]
            ret["inside"] = [ c for c in ccs if cond(c)]
            assert (len(ret['outside'])+len(ret["inside"]) == len(ccs))
            ret["text"] = self._text().possible_text_ccs(image=self.without_insidestaves_info(),ccs=ret["outside"])
            self._ccs = ret
        else:
            self.l.debug("Cached")
            ret = self._ccs

        if not "classified" in ret and not self.classifier is None:
           ret["classified"] = self._classified_ccs(ccs_remove(ret['outside'],ret['text']))
           self._ccs = ret

        return ret
Exemple #2
0
def _rembase(staffpos, image):
    if isinstance(image, gamera.core.Image):
        ccs = image.cc_analysis()
    else:
        ccs = image
    cond = inout_staff_condition(staffpos)
    return ccs, cond
Exemple #3
0
def _rembase(staffpos,image):
    if isinstance(image,gamera.core.Image):
        ccs = image.cc_analysis()
    else:
        ccs = image
    cond = inout_staff_condition(staffpos)
    return ccs,cond
Exemple #4
0
    def ccs_overall(self):
        """ Segment image in inside/outside staves,text,dynamics and return the
        ccs for each of these segments as a dict:
            return {
                     'all'
                     'outside'
                     'inside'
                     'text'
                     'classified'
                }
        """
        ret = {}
        if self._ccs is None:
            baseimg = self.without_staves()
            ccs = set(baseimg.cc_analysis())
            stavey = self.ms().get_staffpos()
            if stavey is None:
                raise NoStavesException, "No stafflines, no need for anything here.  Abort"
            cond = inout_staff_condition(self.ms().get_staffpos())
            ret["all"] = ccs
            ret["outside"] = [c for c in ccs if not cond(c)]
            ret["inside"] = [c for c in ccs if cond(c)]
            assert (len(ret['outside']) + len(ret["inside"]) == len(ccs))
            ret["text"] = self._text().possible_text_ccs(
                image=self.without_insidestaves_info(), ccs=ret["outside"])
            self._ccs = ret
        else:
            self.l.debug("Cached")
            ret = self._ccs

        if not "classified" in ret and not self.classifier is None:
            ret["classified"] = self._classified_ccs(
                ccs_remove(ret['outside'], ret['text']))
            self._ccs = ret

        return ret
Exemple #5
0
from sheetmusic import MusicImage
from within import inout_staff_condition
import os.path
if os.path.isfile("lvbp0.tif"):
    mi = MusicImage("lvbp0.tif")
    rgb = mi.to_rgb().to_onebit().to_rgb()
    # Painting inside staff things green
    cond = inout_staff_condition(mi.ms().get_staffpos())
    ccs = [ c for c in mi.ccs(False,False) if cond(c)]
    for c in ccs:
        rgb.highlight(c,RGBPixel(0,255,0))
    # Painting relevant ccs' red.
    ccs = mi.ccs()
    for c in ccs:
        rgb.highlight(c,RGBPixel(255,0,0))
    # Painting text yellow
    ccs = mi.possible_text_ccs()
    for c in ccs:
        rgb.highlight(c,RGBPixel(255,255,0))
    rgb.save_PNG("lvbp0_relevant_ccs.png")

mi = MusicImage("debussyp0.tif")
rgb = mi.to_rgb().to_onebit().to_rgb()

cond = inout_staff_condition(mi.ms().get_staffpos())
ccs = [ c for c in mi.ccs(False,False) if cond(c)]
for c in ccs:
    rgb.highlight(c,RGBPixel(0,255,0))
ccs = mi.ccs()
for c in ccs:
    rgb.highlight(c,RGBPixel(255,0,0))
Exemple #6
0
from sheetmusic import MusicImage
from within import inout_staff_condition
import os.path
if os.path.isfile("lvbp0.tif"):
    mi = MusicImage("lvbp0.tif")
    rgb = mi.to_rgb().to_onebit().to_rgb()
    # Painting inside staff things green
    cond = inout_staff_condition(mi.ms().get_staffpos())
    ccs = [c for c in mi.ccs(False, False) if cond(c)]
    for c in ccs:
        rgb.highlight(c, RGBPixel(0, 255, 0))
    # Painting relevant ccs' red.
    ccs = mi.ccs()
    for c in ccs:
        rgb.highlight(c, RGBPixel(255, 0, 0))
    # Painting text yellow
    ccs = mi.possible_text_ccs()
    for c in ccs:
        rgb.highlight(c, RGBPixel(255, 255, 0))
    rgb.save_PNG("lvbp0_relevant_ccs.png")

mi = MusicImage("debussyp0.tif")
rgb = mi.to_rgb().to_onebit().to_rgb()

cond = inout_staff_condition(mi.ms().get_staffpos())
ccs = [c for c in mi.ccs(False, False) if cond(c)]
for c in ccs:
    rgb.highlight(c, RGBPixel(0, 255, 0))
ccs = mi.ccs()
for c in ccs:
    rgb.highlight(c, RGBPixel(255, 0, 0))