Beispiel #1
0
    def classify_image(self,imgname,ccs = None):
        if hasattr(imgname,'ccs'):
            mi = imgname
        else:
            from sheetmusic import MusicImage
            self.l.debug("Loading image from file %s",imgname)
            mi = MusicImage(imgname)

        if ccs is None:
            self.l.debug("Getting relevant ccs.")
            relevant_cc = mi.ccs(remove_text=True,remove_inside_staffs=True)
        else:
            relevant_cc = ccs
        ret = Classified_image(self,mi,relevant_cc)
        self.images.append(ret)
        return ret
Beispiel #2
0
    def classify_image(self, imgname, ccs=None):
        if hasattr(imgname, 'ccs'):
            mi = imgname
        else:
            from sheetmusic import MusicImage
            self.l.debug("Loading image from file %s", imgname)
            mi = MusicImage(imgname)

        if ccs is None:
            self.l.debug("Getting relevant ccs.")
            relevant_cc = mi.ccs(remove_text=True, remove_inside_staffs=True)
        else:
            relevant_cc = ccs
        ret = Classified_image(self, mi, relevant_cc)
        self.images.append(ret)
        return ret
Beispiel #3
0

if __name__ == '__main__':
    from gamera.core import *
    import sys
    import re
    import time
    from sheetmusic import MusicImage
    from within import inout_vertical_ys
    from numpy import average
    init_gamera()
    for i, imgname in enumerate(sys.argv[1:]):
        m = re.match(r"^(.*)\.[^\.]+$", imgname)
        noend = m.group(1)
        start = time.time()
        i = MusicImage(imgname)
        print "Load image %f" % (time.time() - start)
        start = time.time()
        spikes = i.possible_text_areas()
        print "Spikes %f" % (time.time() - start)
        start = time.time()
        ccs = i.without_insidestaves_info().cc_analysis()
        print "ccanalysis %f" % (time.time() - start)
        sys.stdout.flush()
        for s in spikes:
            cond = inout_vertical_ys([(s['start'], s['stop'])])
            cs = [c for c in ccs if cond(c)]
            print "%d ccs in ys: %d-%d" % (len(cs), s['start'], s['stop'])
            avgaspect = average([c.aspect_ratio() for c in cs])
            print "%f mean aspect" % (avgaspect)
            print
Beispiel #4
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))
Beispiel #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))
Beispiel #6
0

if __name__ == '__main__':
    from gamera.core import *
    import sys
    import re
    import time
    from sheetmusic import MusicImage
    from within import inout_vertical_ys
    from numpy import average
    init_gamera()
    for i,imgname in enumerate(sys.argv[1:]):
        m = re.match(r"^(.*)\.[^\.]+$",imgname)
        noend = m.group(1)
        start = time.time()
        i = MusicImage(imgname)
        print "Load image %f"%(time.time()-start)
        start = time.time()
        spikes = i.possible_text_areas()
        print "Spikes %f"%(time.time()-start)
        start=time.time()
        ccs = i.without_insidestaves_info().cc_analysis()
        print "ccanalysis %f"%(time.time()-start)
        sys.stdout.flush()
        for s in spikes:
            cond = inout_vertical_ys([(s['start'],s['stop'])])
            cs = [ c for c in ccs if cond(c) ]
            print "%d ccs in ys: %d-%d"%(len(cs),s['start'],s['stop'])
            avgaspect = average([ c.aspect_ratio() for c in cs ])
            print "%f mean aspect"%(avgaspect)
            print
Beispiel #7
0
import sys
import re
import yaml
sys.path.append("..")
from sheetmusic import MusicImage


if __name__ == '__main__':
    FORMAT = "%(asctime)-15s %(levelname)s [%(name)s.%(funcName)s]  %(message)s"
    logging.basicConfig(level=logging.DEBUG,format=FORMAT,filename="counter.log")
    init_gamera()

    for imgname in sys.argv[1:]:
        m = re.match(r"^(.*)\.[^\.]+$",imgname)
        noend = m.group(1)
        mi = MusicImage(imgname,training_filename="../preomr_edited_cnn.xml")
        c = mi.ccs_overall()
        cl = dict([ (k,len(v)) for k,v in c.iteritems() ])
        outf = "%s-colorseg.yaml"%noend
        with open(outf,"w") as f:
            data = {'text':{'found':cl['text'],'count':cl['text']},
                    'dynamics':{'found':cl['classified'], 'count':cl['classified']
                               }
                   }
            print "%s"%data
            yaml.dump(data,f)
        logging.debug("Wrote %s",outf)



Beispiel #8
0
import re
import yaml
sys.path.append("..")
from sheetmusic import MusicImage

if __name__ == '__main__':
    FORMAT = "%(asctime)-15s %(levelname)s [%(name)s.%(funcName)s]  %(message)s"
    logging.basicConfig(level=logging.DEBUG,
                        format=FORMAT,
                        filename="counter.log")
    init_gamera()

    for imgname in sys.argv[1:]:
        m = re.match(r"^(.*)\.[^\.]+$", imgname)
        noend = m.group(1)
        mi = MusicImage(imgname, training_filename="../preomr_edited_cnn.xml")
        c = mi.ccs_overall()
        cl = dict([(k, len(v)) for k, v in c.iteritems()])
        outf = "%s-colorseg.yaml" % noend
        with open(outf, "w") as f:
            data = {
                'text': {
                    'found': cl['text'],
                    'count': cl['text']
                },
                'dynamics': {
                    'found': cl['classified'],
                    'count': cl['classified']
                }
            }
            print "%s" % data