Commit eccb750f authored by Luciano Jung's avatar Luciano Jung
Browse files

Add barrel distortion code

parent b6a812f5
from wand.image import Image
import numpy as np
import cv2 as cv
from PIL import Image as PILImg
imagepath = 'data/'
imagenames = ['1_1']
imagetype = '.png'
def readImage_as_c2(imagename):
img = cv.imread(imagepath + imagename + imagetype)
return img
def read_image(imagename):
img = Image(filename=(imagepath + imagename + imagetype))
return img
def transform_fingerprint_barrel(img):
print(img.size)
img.virtual_pixel = 'white'
img.distort('barrel', (0, 0.5, 0, 0.5, 0, 0.5, 0, 0.5))
return img
def show_image(img):
# convert to opencv/numpy array format
img_opencv = convert_image_to_cv2(img)
# display result with opencv
cv.imshow("BARREL", img_opencv)
cv.waitKey(0)
def convert_cv2_to_image(img: np.ndarray) -> Image:
return PILImg.fromarray(cv.cvtColor(img, cv.COLOR_BGR2RGB))
# return PILImg.fromarray(img)
def convert_image_to_cv2(img: Image) -> np.ndarray:
# return cv2.cvtColor(numpy.array(img), cv2.COLOR_RGB2BGR)
return np.asarray(img)
def squeeze_image(img, factors):
width, height = img.size
img = convert_image_to_cv2(img)
dsize = ((int)(width * factors[0]), (int)(height * factors[1]))
# resize image
img = cv.resize(img, dsize, interpolation=cv.INTER_AREA)
img = convert_cv2_to_image(img)
return img
# do transformation for each image
for imagename in imagenames:
img = read_image(imagename)
img = transform_fingerprint_barrel(img)
img = squeeze_image(img, [1, 1.5])
# save_image(img, imagename + '_distorted')
show_image(img)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment