예제 #1
0
파일: draw.py 프로젝트: DDMAL/Gamera
 def __doc_example1__(images):
     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
     points = [(randint(0, 100), randint(0, 100)) for x in range(4)]
     image.draw_bezier(*tuple(list(points) + [RGBPixel(255, 0, 0), 0.1]))
     image.draw_marker(points[0], 7, 0, RGBPixel(0, 0, 255))
     image.draw_marker(points[1], 7, 1, RGBPixel(0, 255, 0))
     image.draw_marker(points[2], 7, 1, RGBPixel(0, 255, 0))
     image.draw_marker(points[3], 7, 0, RGBPixel(0, 0, 255))
     return image
예제 #2
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)
     points = [(randint(0, 100), randint(0, 100)) for x in range(4)]
     image.draw_bezier(*tuple(list(points) + [RGBPixel(255, 0, 0), 0.1]))
     image.draw_marker(points[0], 7, 0, RGBPixel(0, 0, 255))
     image.draw_marker(points[1], 7, 1, RGBPixel(0, 255, 0))
     image.draw_marker(points[2], 7, 1, RGBPixel(0, 255, 0))
     image.draw_marker(points[3], 7, 0, RGBPixel(0, 0, 255))
     return image
예제 #3
0
파일: draw.py 프로젝트: hsnr-gamera/gamera
 def __doc_example1__(images):
   from random import randint, seed
   from gamera.core import Image, Dim
   seed(0)
   image = Image((0, 0), Dim(100, 100), RGB, DENSE)
   points = [(randint(0, 100), randint(0, 100)) for x in range(4)]
   image.draw_bezier(*tuple(list(points) + [RGBPixel(255, 0, 0), 0.1]))
   image.draw_marker(points[0], 7, 0, RGBPixel(0, 0, 255))
   image.draw_marker(points[1], 7, 1, RGBPixel(0, 255, 0))
   image.draw_marker(points[2], 7, 1, RGBPixel(0, 255, 0))
   image.draw_marker(points[3], 7, 0, RGBPixel(0, 0, 255))
   return image
예제 #4
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
예제 #5
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