-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspacial_transformation.py
70 lines (55 loc) · 1.82 KB
/
spacial_transformation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import print_function
import numpy as np
import cv2
from imaugtools import center_crop, crop_around_center
from PIL import Image, ImageFilter
def image_zoom(image, param=1.5):
""" param: 1-2 """
res = cv2.resize(image, None, fx=param, fy=param, interpolation=cv2.INTER_LINEAR)
# res = crop_around_center(res, (image.shape))
if param >= 1:
res = crop_around_center(res, (image.shape))
else:
res = center_crop(res, (image.shape))
return res
def image_blur(image, params=2):
# blur = cv2.blur(image, (params+1, params+1))
image_data = image.squeeze().astype("uint8")
image = Image.fromarray(image_data)
gaussImage = image.filter(ImageFilter.GaussianBlur(params))
image_blur = np.asarray(gaussImage)
# image_blur = skimage.filters.gaussian(
# image.squeeze(), sigma=(1.0, 1.0), truncate=2, multichannel=True)
return image_blur
def image_brightness(image, param=128):
image = np.int16(image)
image = image + param
image = np.clip(image, 0, 255)
image = np.uint8(image)
return image
def image_contrast(image, param=1.5):
"""
param: 0-2
"""
image = np.int16(image)
image = (image-127) * param + 127
image = np.clip(image, 0, 255)
image = np.uint8(image)
return image
def image_translation_cropped(img, params):
if len(img.shape) == 2:
rows, cols = img.shape
else:
rows, cols, ch = img.shape
M = np.float32([[1, 0, params], [0, 1, params]])
dst = cv2.warpAffine(img, M, (cols, rows))
return dst
def image_shear_cropped(img, params):
if len(img.shape) == 2:
rows, cols = img.shape
else:
rows, cols, ch = img.shape
factor = params*(-1.0)
M = np.float32([[1, factor, 0], [factor, 1, 0]])
dst = cv2.warpAffine(img, M, (cols, rows))
return dst