Esempio n. 1
0
    def ccs(self,remove_text=True,remove_inside_staffs=True,remove_classified=False):
        """ Return the connected components of the image
        Choose to get all, or with some parts removed

        Keyword arguments:
            remove_text --- Remove any thing that looks like text from the list
            off ccs
            remove_inside_staffs --- Remove all cc's  that overlap with the
            stafflines.
        """
        self.l.debug("remove_text=%s, remove_inside_staffs=%s, remove_classified=%s",\
                     remove_text,remove_inside_staffs,remove_classified)
        c = self.ccs_overall()

        ccs = c["all"]


        if (remove_text):
            inccs = c["text"]
            self.l.debug("Removing %d ccs as text",len(inccs))
            ccs = ccs_remove(ccs,inccs)

        if (remove_inside_staffs):
            pre = ccs
            ccs = ccs_intersect(ccs,c["outside"])
            self.l.debug("Removing %d ccs as inside staffs",(len(pre)-len(ccs)))

        if (remove_classified):
            clasccs = ret["classified"]
            self.l.debug("Removing %d ccs as classified",(len(classcs)))
            ccs = ccs_remove(ccs,clasccs)
        return ccs
Esempio n. 2
0
    def ccs(self,
            remove_text=True,
            remove_inside_staffs=True,
            remove_classified=False):
        """ Return the connected components of the image
        Choose to get all, or with some parts removed

        Keyword arguments:
            remove_text --- Remove any thing that looks like text from the list
            off ccs
            remove_inside_staffs --- Remove all cc's  that overlap with the
            stafflines.
        """
        self.l.debug("remove_text=%s, remove_inside_staffs=%s, remove_classified=%s",\
                     remove_text,remove_inside_staffs,remove_classified)
        c = self.ccs_overall()

        ccs = c["all"]

        if (remove_text):
            inccs = c["text"]
            self.l.debug("Removing %d ccs as text", len(inccs))
            ccs = ccs_remove(ccs, inccs)

        if (remove_inside_staffs):
            pre = ccs
            ccs = ccs_intersect(ccs, c["outside"])
            self.l.debug("Removing %d ccs as inside staffs",
                         (len(pre) - len(ccs)))

        if (remove_classified):
            clasccs = ret["classified"]
            self.l.debug("Removing %d ccs as classified", (len(classcs)))
            ccs = ccs_remove(ccs, clasccs)
        return ccs
Esempio n. 3
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
Esempio n. 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