Exemplo n.º 1
0
def test_rotate():
    img = cv.imread('data/original_images/lenna.png')
    ip = imagewizard.Processing()

    # res1 = ip.rotate(img, 90, order='bgr')
    # res2 = ip.rotate(img, 180, order='bgr')
    # res3 = ip.rotate(img, 270, order='bgr')
    # res4 = ip.rotate(img, 315, scaling_factor=0.5, order='bgr')
    # res5 = ip.rotate(img, 45, scaling_factor=2, order='bgr')
    
    # cv.imshow('original', img)
    # cv.imshow('res1', res1)
    # cv.imshow('res2', res2)
    # cv.imshow('res3', res3)
    # cv.imshow('res4', res4)
    # cv.imshow('res5', res5)

    # cv.imwrite('rotate-90deg.png', res1)
    # cv.imwrite('rotate-180deg.png', res2)
    # cv.imwrite('rotate-270deg.png', res3)
    # cv.imwrite('rotate-315deg-scale.png', res4)
    # cv.imwrite('rotate-45deg-scale.png', res5)

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 2
0
def test_lum():
    img = cv.imread('data/original_images/lenna.png')
    ip = imagewizard.Processing()

    lum_100 = ip.luminosity(img, 100, 'bgr')
    lum_150 = ip.luminosity(img, 150, 'bgr')
    lum_255 = ip.luminosity(img, 255, 'bgr')

    lum_neg_100 = ip.luminosity(img, -100, 'bgr')
    lum_neg_255 = ip.luminosity(img, -255, 'bgr')

    # cv.imshow("original image", img)
    # cv.imshow('lum 100', lum_100)
    # cv.imshow('lum 150', lum_150)
    # cv.imshow('lum -100', lum_neg_100)

    # cv.imshow('lum 255', lum_255)
    # cv.imshow('lum -255', lum_neg_255)

    cv.imwrite('lum_100.png', lum_100)
    cv.imwrite('lum_neg_100.png', lum_neg_100)
    

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 3
0
def test_skew():
    img = cv.imread('data/original_images/skew.png')
    ip = imagewizard.Processing()
    
    # # input_points: three points on input image, ex: np.float32([[50,50],[200,50],[50,200]])
    # ip_points = np.float32([[50,50],[200,50],[50,200]])
    # # output_points: three points on output location correspoinding to input_points' to be transformed, np.float32([[10,100],[200,50],[100,250]])
    # op_points = np.float32([[10,100],[200,50],[100,250]])

    # skew_affine = ip.skew_affine(img, ip_points, op_points, 'bgr')
    
    # input_points: four points on input image, ex: np.float32([[56,65],[368,52],[28,387],[389,390]])
    # [(73, 239), (356, 117), (475, 265), (187, 443)]
    # ip_per = np.float32([(250, 165), (631, 405), (98, 428), (474, 596)])
    
    # ip_per = np.float32([(100, 320), (475, 160), (640, 340), (250, 580)])
    # # output_points: four points on output location correspoinding to input_points' to be transformed, ex: np.float32([[0,0],[300,0],[0,300],[300,300]])
    # op_per = np.float32([[0,0], [300,0], [300,300], [0,300]])

    ip_per = np.float32([(100, 320), (472, 156), (250, 580), (630, 345)])
    op_per = np.float32([[0,0], [500,0], [0,350], [500,350]])

    skew_per = ip.skew_perspective(img, ip_per, op_per, 'bgr')

    cv.imshow("original", img)
    # cv.imshow("skew affine image", skew_affine)
    cv.imshow("skew perspective image", skew_per)

    cv.imwrite('skew_per.png', skew_per)
    

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 4
0
def test_colorspaces():
    img = cv.imread('data/test.png')
    improcess = imagewizard.Processing()
    res = improcess.img2grayscale(img, True)

    cv.imshow('original', img)
    cv.imshow('processed', res)
    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 5
0
def test_resize_zoom():
    img = cv.imread('data/test.png')
    ip = imagewizard.Processing()
    
    # res = ip.resize(img, resize_percentage = 50, order = 'bgr')
    res = ip.resize(img, resize_width=300, resize_height=300, order = 'bgr')
    # dim = (2000, 2000)
    # interpolation = cv.INTER_LINEAR
    # res = cv.resize(img, dim, interpolation=interpolation)

    # cv.imshow('Original Image', img)
    # cv.imshow('Resized Image (zoom)', res)
    cv.imwrite('shrink-300px-300px.png', res)
Exemplo n.º 6
0
def test_skew_affine():
    img = cv.imread('data/original_images/skew_aff_org.png')
    ip = imagewizard.Processing()
    
    ip_aff = np.float32([[50,50],[200,50],[50,200]])
    op_aff = np.float32([[10,100],[200,50],[100,250]])

    skew_aff = ip.skew_affine(img, ip_aff, op_aff, order='bgr')

    cv.imshow("original", img)
    cv.imshow("skew affine image", skew_aff)
    cv.imwrite('skew_aff.png', skew_aff)
    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 7
0
def test_binarize():
    image = cv.imread('data/original_images/lenna.png')
    # cv.imshow("Original Image", image)
    # cv.imwrite('org_lenna.png', image)

    ip = imagewizard.Processing()
    # cv.imshow("inverted Image", cv.bitwise_not(image))

    """
    inv_img = ip.img2grayscale(image, inverted=True, is_gray=False, order = 'bgr')
    cv.imshow("inverted Image", cv.bitwise_not(image))
    cv.imwrite('clr_inverted.png', inv_img)

    gray_image = ip.img2grayscale(image, inverted=True, order = 'bgr')
    cv.imshow("Gray Inverted", gray_image)
    cv.imwrite('gray_inverted.png', gray_image)

    trunc_inv_image = ip.img2grayscale(image, trunc=True, inverted=True, order = 'bgr')
    cv.imshow("Trunc Inverted", trunc_inv_image)
    cv.imwrite('trunc_inverted.png', trunc_inv_image)

    gray_image = ip.img2grayscale(image, order = 'bgr')
    cv.imshow("Gray", gray_image)
    cv.imwrite('gray.png', gray_image)
    
    binary_image = ip.img2grayscale(image, to_binary=True, order = 'bgr')
    cv.imshow("Binary Threshold", binary_image)
    cv.imwrite('binary_img.png', binary_image)

    binary_inv_image = ip.img2grayscale(image, to_binary=True, inverted=True, order = 'bgr')
    cv.imshow("Binary Threshold Inverted Image", binary_inv_image)
    cv.imwrite('binary_inv_image.png', binary_inv_image)

    trunc_image = ip.img2grayscale(image, trunc=True, order = 'bgr')
    cv.imshow("Trucated Threshold Image", trunc_image)
    cv.imwrite('trunc_image.png', trunc_image)

    to_zero_image = ip.img2grayscale(image, to_zero=True, order = 'bgr')
    cv.imshow("To Zero Image", to_zero_image)
    cv.imwrite('to_zero_image.png', to_zero_image)

    to_zero_inverted = ip.img2grayscale(image, to_zero=True, inverted = True, order = 'bgr')
    cv.imshow("To Zero Inverted Image", to_zero_inverted)
    cv.imwrite('to_zero_inverted.png', to_zero_inverted)
    """

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 8
0
def test_crop():
    img = cv.imread('data/original_images/street.png')
    ip = imagewizard.Processing()
    # crop1 = ip.crop(img, start_x = 50, end_x = 100, start_y = 50, end_y = 100, is_percentage=True, order='bgr')
    # crop2 = ip.crop(img, 400, 1000, 0, 500, is_percentage=False, order='bgr')
    crop3 = ip.crop(img, 0, 50, 0, 50, is_percentage=True, order='bgr')
    # cv.imshow('original', img)
    # cv.imshow('cropped 1', crop1)
    # cv.imshow('cropped 2', crop2)
    cv.imshow('cropped 3', crop3)
    # cv.imwrite('crop1.png', crop1)
    # cv.imwrite('crop2.png', crop2)
    cv.imwrite('crop3.png', crop3)

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 9
0
def test_mirror():
    img = cv.imread('data/original_images/lenna.png')
    ip = imagewizard.Processing()

    mir_x = ip.mirror(img, flip_code=1, order='bgr')
    mir_y = ip.mirror(img, flip_code=0, order='bgr')
    mir_xy = ip.mirror(img, flip_code=-1, order='bgr')

    cv.imshow('flip image around X axis', mir_x)
    cv.imshow('flip image around Y axis', mir_y)
    cv.imshow('flip image around both X & Y axis', mir_xy)
    
    cv.imwrite('flip_x.png', mir_x)
    cv.imwrite('flip_y.png', mir_y)
    cv.imwrite('flip_xy.png', mir_xy)

    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 10
0
def test_segmentation():
    img = cv.imread('data/original_images/lenna.png')
    img1 = Image.open('data/original_images/lenna.png')

    colors = [[224, 166, 147], [110, 34, 71], [195, 98, 100]]

    ip = imagewizard.Processing()

    cv_res = ip.segmentation(img, colors, 'bgr')
    pil_res = ip.segmentation(img1, colors, 'rgb')

    pil_res_im = Image.fromarray(pil_res)

    cv.imshow("original image", img)
    cv.imshow('cv result', cv_res)
    pil_res_im.show()
    pil_res_im.save("segmented_image.png")
    cv.waitKey(0)
    cv.destroyAllWindows()
Exemplo n.º 11
0
def test_blur():
    img = cv.imread('data/original_images/street.png')
    ip = imagewizard.Processing()

    blur5 = ip.blur(img, blur_level=5, order='bgr')
    blur25 = ip.blur(img, blur_level=25, order='bgr')
    blur50 = ip.blur(img, blur_level=50, order='bgr')

    cv.imshow("original image", img)
    cv.imshow('blur 5', blur5)
    cv.imshow('blur 25', blur25)
    cv.imshow('blur 50', blur50)

    cv.imwrite('blur5.png', blur5)
    cv.imwrite('blur25.png', blur25)
    cv.imwrite('blur50.png', blur50)

    cv.waitKey(0)
    cv.destroyAllWindows()
class TestProcessing(unittest.TestCase):

    im_pro = imagewizard.Processing()
    street_org = cv.imread("data/original_images/street.png")
    lenna_org = cv.imread("data/original_images/lenna.png")

    # resize tests
    resize_actual = cv.imread(
        "data/processed_images/resize/shrink-300px-300px.png")
    resize_test = im_pro.resize(street_org,
                                resize_width=300,
                                resize_height=300,
                                order='bgr')

    # grayscale tests
    img2grayscale_actual = cv.imread("data/processed_images/gray/gray.png",
                                     cv.IMREAD_GRAYSCALE)
    img2grayscale_test = im_pro.img2grayscale(lenna_org, order='bgr')

    img2grayscale_inv_actual = cv.imread(
        "data/processed_images/gray/gray_inverted.png", cv.IMREAD_GRAYSCALE)
    img2grayscale_inv_test = im_pro.img2grayscale(lenna_org,
                                                  inverted=True,
                                                  order='bgr')

    grayscale_actual = [img2grayscale_actual, img2grayscale_inv_actual]
    grayscale_test = [img2grayscale_test, img2grayscale_inv_test]

    # rotate tests
    rotate_actual = cv.imread("data/processed_images/rotate/rotate-90deg.png")
    rotate_test = im_pro.rotate(lenna_org, rotation_degree=90, order='bgr')

    # crop tests
    crop_actual = cv.imread("data/processed_images/crop/crop1.png")
    crop_test = im_pro.crop(street_org,
                            start_x=50,
                            end_x=100,
                            start_y=50,
                            end_y=100,
                            is_percentage=True,
                            order='bgr')

    # mirror tests
    mirror_actual = cv.imread("data/processed_images/mirror/flip_x.png")
    mirror_test = im_pro.mirror(lenna_org, flip_code=1, order='bgr')

    # blur tests
    blur_actual = cv.imread("data/processed_images/blur/blur5.png")
    blur_test = im_pro.blur(street_org, blur_level=5, order='bgr')

    # luminosity tests
    lum_actual = cv.imread("data/processed_images/luminosity/lum_100.png")
    lum_test = im_pro.luminosity(lenna_org, intensity_shift=100, order='bgr')

    # segmentation tests
    rgb_colors_list = [[224, 166, 147], [110, 34, 71], [195, 98, 100]]
    seg_actual = cv.imread("data/processed_images/segmented_image.png")
    seg_test = im_pro.segmentation(lenna_org, rgb_colors_list, 'bgr')

    def test_resize(self):
        npt.assert_array_equal(self.resize_test, self.resize_actual,
                               'Resized image does not equal actual result')

    def test_grayscale(self):
        npt.assert_array_equal(
            self.grayscale_actual, self.grayscale_test,
            'img2grayscale result does not equal actual result')

    def test_rotate(self):
        npt.assert_array_equal(self.rotate_actual, self.rotate_test,
                               'Rotated image does not equal actual result')

    def test_crop(self):
        npt.assert_array_equal(self.crop_actual, self.crop_test,
                               'Cropped image does not equal actual result')

    def test_mirror(self):
        npt.assert_array_equal(
            self.mirror_actual, self.mirror_test,
            'Mirrored flip X image does not equal actual result')

    def test_blur(self):
        npt.assert_array_equal(self.blur_actual, self.blur_test,
                               'Blurred image does not equal actual result')

    def test_luminosity(self):
        npt.assert_array_equal(
            self.lum_actual, self.lum_test,
            'luminosity 100 image does not equal actual result')

    def test_segmentation(self):
        npt.assert_array_equal(
            self.seg_actual, self.seg_test,
            'segmentation image does not equal actual result')