コード例 #1
0
ファイル: draw.py プロジェクト: DDMAL/Gamera
 def __doc_example1__(images):
     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
     for i in range(10):
         image.draw_filled_rect((randint(0, 100), randint(0, 100)),
                                (randint(0, 100), randint(0, 100)),
                                RGBPixel(randint(0, 255), randint(0, 255), randint(0, 255)))
     return image
コード例 #2
0
ファイル: draw.py プロジェクト: elaboris/gamera
 def __doc_example1__(images):
   from random import randint
   from gamera.core import Image, Dim
   image = Image((0, 0), Dim(100, 100), RGB, DENSE)
   for i in range(10):
     image.draw_filled_rect((randint(0, 100), randint(0, 100)),
                            (randint(0, 100), randint(0, 100)),
                            RGBPixel(randint(0, 255), randint(0,255), randint(0, 255)))
   return image
コード例 #3
0
ファイル: draw.py プロジェクト: alan0526/Gamera
 def __doc_example1__(images):
     from random import randint
     from gamera.core import Image, Dim
     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
     for i in range(10):
         image.draw_filled_rect((randint(0, 100), randint(0, 100)),
                                (randint(0, 100), randint(0, 100)),
                                RGBPixel(randint(0, 255), randint(0, 255),
                                         randint(0, 255)))
     return image
コード例 #4
0
ファイル: geometry.py プロジェクト: DDMAL/Gamera
 def __doc_example1__(images):
     from gamera.core import Image, RGBPixel, Point as P
     img = Image((0, 0), (90, 90))
     points = [P(10, 10), P(20, 30), P(32, 22), P(85, 14), P(40, 70), P(80, 85)]
     for p in points:
         img.draw_filled_rect((p.x - 2, p.y - 2), (p.x + 1, p.y + 1), 1)
     r = img.max_empty_rect()
     rgb = img.to_rgb()
     rgb.draw_hollow_rect(r, RGBPixel(255, 0, 0))
     rgb.highlight(img, RGBPixel(0, 0, 0))
     return [rgb]
コード例 #5
0
 def __doc_example1__(images):
     from gamera.core import Image
     from gamera.core import Point as P
     img = Image((0, 0), (90, 90))
     points = [
         P(10, 10),
         P(20, 30),
         P(32, 22),
         P(85, 14),
         P(40, 70),
         P(80, 85)
     ]
     for p in points:
         img.draw_filled_rect((p.x - 2, p.y - 2), (p.x + 1, p.y + 1), 1)
     r = img.max_empty_rect()
     rgb = img.to_rgb()
     rgb.draw_hollow_rect(r, RGBPixel(255, 0, 0))
     rgb.highlight(img, RGBPixel(0, 0, 0))
     return [rgb]
コード例 #6
0
    def show_result(self, highlight_groups=True):
        """Returns an RGB image with the found staff lines highlighted.

Parameters:

  *highlight_groups*:
    when *True* (default), each stave system is underlayed in a different
    color. When false, only the edge points are marked in different colors,
    which is less visible for skeleton or average staff line representation.
"""
        rgb = Image(self.image, RGB)
        if highlight_groups:
            # highlight staff systems
            for staffno, staff in enumerate(self.linelist):
                if not staff:
                    continue
                staffcolor = RGBPixel(190 + (11*staffno) % 66, \
                                      190 + (31*(staffno + 1)) % 66, \
                                      190 + (51*(staffno + 2)) % 66)
                topline = staff[0].to_average()
                botline = staff[-1].to_average()
                leftx = min([topline.left_x, botline.left_x])
                rightx = max([topline.right_x, botline.right_x])
                topy = topline.average_y
                boty = botline.average_y
                border = max(
                    [self.staffspace_height / 2, self.staffline_height * 4])
                if leftx - border > 0:
                    leftx -= border
                if rightx + border < rgb.ncols:
                    rightx += border
                if topy - border > 0:
                    topy -= border
                if boty + border < rgb.nrows:
                    boty += border
                rgb.draw_filled_rect((leftx, topy), (rightx, boty), staffcolor)

        # draw original image
        rgb.highlight(self.image, RGBPixel(0, 0, 0))

        for staffno, staff in enumerate(self.linelist):
            if not staff:
                continue
            if highlight_groups:
                staffcolor = RGBPixel(255, 0, 0)
            else:
                staffcolor = RGBPixel((53*(staffno)) % 256,\
                                      (111*(staffno+1)) % 256,\
                                      (111*(staffno+2)) % 256)

            for line in staff:
                if isinstance(line, StafflinePolygon):
                    lastp = None
                    for p in line.vertices:
                        rgb.draw_marker(p,self.staffline_height*2,3,\
                                        staffcolor)
                        if lastp:
                            rgb.draw_line(lastp, p, RGBPixel(255, 0, 0))
                        lastp = p
                elif isinstance(line, StafflineAverage):
                    rgb.draw_line(Point(0,line.average_y),\
                                  Point(rgb.ncols,line.average_y),\
                                  RGBPixel(255,0,0))
                    rgb.draw_marker(Point(line.left_x,line.average_y),\
                                    self.staffline_height*2,3,\
                                    staffcolor)
                    rgb.draw_marker(Point(line.right_x,line.average_y),\
                                    self.staffline_height*2,3,\
                                    staffcolor)
                elif isinstance(line, StafflineSkeleton):
                    # doing this in Python might be too slow,
                    # implement it in C++ later
                    x = line.left_x
                    for y in line.y_list:
                        rgb.set(Point(x, y), RGBPixel(255, 0, 0))
                        x += 1
                    if len(line.y_list) > 0:
                        rgb.draw_marker(Point(line.left_x,line.y_list[0]),\
                                        self.staffline_height*2,3,\
                                        staffcolor)
                        rgb.draw_marker(Point(x-1,line.y_list[-1]),\
                                        self.staffline_height*2,3,\
                                        staffcolor)
        return rgb
コード例 #7
0
    def show_result(self, highlight_groups=True):
        """Returns an RGB image with the found staff lines highlighted.

Parameters:

  *highlight_groups*:
    when *True* (default), each stave system is underlayed in a different
    color. When false, only the edge points are marked in different colors,
    which is less visible for skeleton or average staff line representation.
"""
        rgb = Image(self.image, RGB)
        if highlight_groups:
            # highlight staff systems
            for staffno, staff in enumerate(self.linelist):
                if not staff:
                    continue
                staffcolor = RGBPixel(190 + (11*staffno) % 66, \
                                      190 + (31*(staffno + 1)) % 66, \
                                      190 + (51*(staffno + 2)) % 66)
                topline = staff[0].to_average()
                botline = staff[-1].to_average()
                leftx = min([topline.left_x, botline.left_x])
                rightx = max([topline.right_x, botline.right_x])
                topy = topline.average_y
                boty = botline.average_y
                border = max([self.staffspace_height/2, self.staffline_height*4])
                if leftx - border > 0:
                    leftx -= border
                if rightx + border < rgb.ncols:
                    rightx += border
                if topy - border > 0:
                    topy -= border
                if boty + border < rgb.nrows:
                    boty += border
                rgb.draw_filled_rect((leftx, topy), (rightx, boty), staffcolor)

        # draw original image
        rgb.highlight(self.image, RGBPixel(0, 0, 0))

        for staffno, staff in enumerate(self.linelist):
            if not staff:
                continue
            if highlight_groups:
                staffcolor = RGBPixel(255,0,0)
            else:
                staffcolor = RGBPixel((53*(staffno)) % 256,\
                                      (111*(staffno+1)) % 256,\
                                      (111*(staffno+2)) % 256)

            for line in staff:
                if isinstance(line, StafflinePolygon):
                    lastp = None
                    for p in line.vertices:
                        rgb.draw_marker(p,self.staffline_height*2,3,\
                                        staffcolor)
                        if lastp:
                            rgb.draw_line(lastp,p,RGBPixel(255,0,0))
                        lastp = p
                elif isinstance(line, StafflineAverage):
                    rgb.draw_line(Point(0,line.average_y),\
                                  Point(rgb.ncols,line.average_y),\
                                  RGBPixel(255,0,0))
                    rgb.draw_marker(Point(line.left_x,line.average_y),\
                                    self.staffline_height*2,3,\
                                    staffcolor)
                    rgb.draw_marker(Point(line.right_x,line.average_y),\
                                    self.staffline_height*2,3,\
                                    staffcolor)
                elif isinstance(line, StafflineSkeleton):
                    # doing this in Python might be too slow,
                    # implement it in C++ later
                    x = line.left_x
                    for y in line.y_list:
                        rgb.set(Point(x, y), RGBPixel(255, 0, 0))
                        x +=1
                    if len(line.y_list) > 0:
                        rgb.draw_marker(Point(line.left_x,line.y_list[0]),\
                                        self.staffline_height*2,3,\
                                        staffcolor)
                        rgb.draw_marker(Point(x-1,line.y_list[-1]),\
                                        self.staffline_height*2,3,\
                                        staffcolor)
        return rgb