Example #1
0
    def test_regularRotatedPolygon(self):
        # Result image for regularPolygon with rotated points
        regularRotatedImage, regularRotatedCanvas = get_image(
            'L', (640, 480), 'white')

        center = np.array([320, 240])
        draw(regularRotatedCanvas, [center], 'center')
        draw(regularRotatedCanvas, (rotate(
            (regularPolygon(3, np.array([160, 120]), 50)), center, 45.0)),
             '3r')
        draw(regularRotatedCanvas, (rotate(
            (regularPolygon(4, np.array([480, 120]), 90)), center, 45.0)),
             '4r')
        draw(regularRotatedCanvas, (rotate(
            (regularPolygon(5, np.array([420, 360]), 60)), center, 45.0)),
             '5r')
        draw(regularRotatedCanvas, (rotate(
            (regularPolygon(6, np.array([160, 360]), 80)), center, 45.0)),
             '6r')
        draw(regularRotatedCanvas, (rotate(
            (regularPolygon(7, np.array([320, 160]), 70)), center, 45.0)),
             '7r')

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        regularRotatedImage.save(result_file)
        regularRotatedImage.close()

        # compare results against reference data
        validate(reference_file, result_file)
Example #2
0
    def test_scale_transform(self):
        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        # Result image for transform
        result_image, result_canvas = get_image('L', (640, 480), 'white')

        drawSolid(result_canvas, regularPolygon(3, np.array([320, 240]), 50),
                  'black')
        drawSolid(result_canvas, regularPolygon(5, np.array([80, 60]), 70),
                  'black')
        drawSolid(result_canvas, regularPolygon(4, np.array([480, 380]), 70),
                  'black')
        drawWire(
            result_canvas,
            scale(np.array([320, 240]),
                  (regularPolygon(3, np.array([320, 240]), 50)), 3))
        drawWire(
            result_canvas,
            scale(np.array([80, 60]),
                  (regularPolygon(5, np.array([80, 60]), 70)), 1.3))
        drawWire(
            result_canvas,
            scale(np.array([480, 380]),
                  (regularPolygon(4, np.array([480, 380]), 70)), 2))

        result_image.save(result_file)
        result_image.close()

        validate(result_file, result_file)
Example #3
0
    def ttest_randomRotatedPolygon(self):

        randomRotatedImage, randomRotatedCanvas = get_image(
            'L', (640, 480), 'white')

        center = np.array([320, 240])
        draw(randomRotatedCanvas, [center], 'center')

        seed = 5
        draw(randomRotatedCanvas, (rotate(
            (randomPolygon(seed, 3, np.array([160, 120]), 50)), center, 90.0)),
             '3r')
        draw(randomRotatedCanvas, (rotate(
            (randomPolygon(seed, 4, np.array([480, 120]), 90)), center, 90.0)),
             '4r')
        draw(randomRotatedCanvas, (rotate(
            (randomPolygon(seed, 5, np.array([420, 360]), 60)), center, 90.0)),
             '5r')
        draw(randomRotatedCanvas, (rotate(
            (randomPolygon(seed, 6, np.array([160, 360]), 80)), center, 90.0)),
             '6r')
        draw(randomRotatedCanvas, (rotate(
            (randomPolygon(seed, 7, np.array([320, 160]), 70)), center, 90.0)),
             '7r')

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        randomRotatedImage.save(result_file)
        randomRotatedImage.close()

        # compare results against reference data
        validate(reference_file, result_file)
Example #4
0
    def test_regularPolygon(self):
        # Result image for regularPolygon
        regularImage, regularCanvas = get_image('L', (640, 480), 'white')

        draw(regularCanvas, regularPolygon(3, np.array([160, 120]), 50), '3')
        draw(regularCanvas, regularPolygon(4, np.array([480, 120]), 90), '4')
        draw(regularCanvas, regularPolygon(5, np.array([420, 360]), 60), '5')
        draw(regularCanvas, regularPolygon(6, np.array([160, 360]), 80), '6')
        draw(regularCanvas, regularPolygon(7, np.array([320, 160]), 70), '7')

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)
        regularImage.save(result_file)
        regularImage.close()
        # compare results against reference data
        validate(reference_file, result_file)
Example #5
0
    def test_draw(self):
        """ Create the file name and its saving path, and specify the reference file to compare to."""
        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)
        ''' This function is to create an empty image with a specific dimension
            with white background, and black/white colored '''

        image, canvas = get_image('L', (15, 90), 'white')

        for i in range(len(draw_points) - 1):
            draw(canvas, (draw_points[i + 0], draw_points[i + 1]), 'A')
        """ saving the file and closing it """

        image.save(result_file)
        image.close()
        """ validate the resultant file against the reference images"""

        validate(reference_file, result_file)
Example #6
0
    def test_translate_transform(self):

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        # Result image for transform
        result_image, result_canvas = get_image('L', (640, 480), 'white')

        draw(result_canvas,
             translate(regularPolygon(4, (120, 340), 100), 240, 0), "black")
        draw(result_canvas,
             translate(regularPolygon(4, (120, 340), 100), 240, -90), "black")
        draw(result_canvas,
             translate(regularPolygon(4, (120, 340), 100), 339.4, -45),
             "black")

        result_image.save(result_file)
        result_image.close()
        validate(result_file, result_file)
Example #7
0
    def test_Polygonshape(self):
        # Result image for combined shapes
        shapeImage, shapeCanvas = get_image('L', (640, 480), 'white')
        center = np.array([320, 240])

        drawWire(shapeCanvas,
                 (rotate((regularPolygon(3, np.array([320, 240]), 110)),
                         np.array([450, 200]), 30.0)))
        drawWire(shapeCanvas, (rotate(
            (regularPolygon(4, np.array([320, 240]), 120)), center, 45.0)))

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        shapeImage.save(result_file)
        shapeImage.close()

        # compare results against reference data
        validate(reference_file, result_file)
Example #8
0
 def test_rotate_transform(self):
     """ This function is to test rotated points in 2D"""
     # first create an empty white image
     result_image, result_canvas = get_image('L', (640, 480), 'white')
     # get the name through the module name
     image_name = filename(sys._getframe().f_code.co_name)
     # call function get_path from set_para.py to set the path for results and reference folder location
     result_file, reference_file = get_path(image_name)
     # plot the points with no rotation
     draw(result_canvas, self.points, '+')
     # specify the centre for rotation and draw it.
     center = np.array([180, 140])
     draw(result_canvas, [center], 'center')
     # apply rotation and draw the resultant points
     rotatedPoints = rotate(self.points, center, 90.0)
     draw(result_canvas, rotatedPoints, 'X')
     # save it into predetermined file.
     result_image.save(result_file)
     result_image.close()
     # compare results against reference data
     validate(reference_file, result_file)
Example #9
0
    def test_drawWire(self):
        """ Create the file name and its saving path, and specify the reference file to compare to."""

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)
        ''' This function is to create an empty image with a specific dimension
            with white background, and black/white colored '''

        image, canvas = get_image('L', (640, 480), 'white')

        drawWire(canvas, regularPolygon(3, np.array([160, 120]), 50))
        drawWire(canvas, regularPolygon(4, np.array([480, 120]), 90))
        drawWire(canvas, regularPolygon(5, np.array([420, 360]), 60))
        drawWire(canvas, regularPolygon(6, np.array([160, 360]), 80))
        drawWire(canvas, regularPolygon(7, np.array([320, 160]), 70))
        """ saving the file and closing it """

        image.save(result_file)
        image.close()
        """ validate the resultant file against the reference images"""

        validate(reference_file, result_file)
Example #10
0
    def ttest_randomPolygon(self):

        randomImage, randomCanvas = get_image('L', (640, 480), 'white')
        seed = 5
        draw(randomCanvas, randomPolygon(seed, 3, np.array([160, 120]), 200),
             '3r')
        draw(randomCanvas, randomPolygon(seed, 4, np.array([480, 120]), 200),
             '4r')
        draw(randomCanvas, randomPolygon(seed, 5, np.array([480, 360]), 200),
             '5r')
        draw(randomCanvas, randomPolygon(seed, 6, np.array([160, 360]), 200),
             '6r')
        draw(randomCanvas, randomPolygon(seed, 7, np.array([320, 240]), 200),
             '7r')

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)

        randomImage.save(result_file)
        randomImage.close()

        # compare results against reference data
        validate(reference_file, result_file)
Example #11
0
    def test_drawSolid(self):
        """ Create the file name and its saving path, and specify the reference file to compare to."""

        image_name = filename(sys._getframe().f_code.co_name)
        result_file, reference_file = get_path(image_name)
        ''' This function is to create an empty image with a specific dimension
            with white background, and black/white colored '''

        image, canvas = get_image('RGB', (640, 480), 'white')
        '''
        for different representations of colors see
        "https://pillow.readthedocs.io/en/3.0.x/reference/ImageColor.html#color-names"
        '''
        drawSolid(canvas, regularPolygon(3, np.array([160, 120]), 50), 'red')
        drawSolid(canvas, regularPolygon(4, np.array([480, 120]), 90), 'blue')
        drawSolid(canvas, regularPolygon(5, np.array([420, 360]), 60), 'green')
        drawSolid(canvas, regularPolygon(6, np.array([160, 360]), 80), 'black')
        drawSolid(canvas, regularPolygon(7, np.array([320, 160]), 70), 'brown')
        """ saving the file and closing it """
        image.save(result_file)
        image.close()
        """ validate the resultant file against the reference images"""

        validate(reference_file, result_file)