Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YoelShoshan/1c9976eb82b00fa27f0b0491c6093efc to your computer and use it in GitHub Desktop.
Save YoelShoshan/1c9976eb82b00fa27f0b0491c6093efc to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
def base_tens_stats(tens):
print(f'shape={tens.shape} min={tens.min()} mean={tens.mean()} max={tens.max()}')
x = np.random.randint(0,1020, (256,256,20)).astype(np.uint16)
base_tens_stats(x)
M = np.array([[ -9.86677170e-01, -3.59121144e-01, 4.28262177e+02],
[ 3.59121144e-01, -9.86677170e-01, 3.36327148e+02],
[ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]], dtype=np.float32)
y = cv2.warpAffine(x, M[:2,:], x.shape[:2],
borderMode=cv2.BORDER_CONSTANT,
borderValue=0,
flags=cv2.INTER_NEAREST)
print('after transform 1')
base_tens_stats(y)
y = cv2.warpAffine(x, M[:2,:], x.shape[:2],
borderMode=cv2.BORDER_CONSTANT,
borderValue=0,
flags=cv2.INTER_LINEAR)
print('after transform 2')
base_tens_stats(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment