I want to you output from ndimage
rotation function and cv2
defined to make it easy to explain the problem. So I generate empty rectangle and rotate it with cv
and then with scipy
:
import cv2
import numpy as np
from scipy import ndimage
import matplotlib.pyplot as plt
def rotate_image(im, angle):
h, w = im.shape[:2]
rot_mat = cv2.getRotationMatrix2D((w/2, h/2), angle, 1.0)
return cv2.warpAffine(im, rot_mat, (w, h), flags=2)
img = np.zeros((300, 200))
img[10:290, 10:190] = 255
cv2.imwrite('img.png', img)
cv2.imwrite('cv2_rot.png', rotate_image(img, -30))
cv2.imwrite('scipy_rot.png', ndimage.rotate(img, -30))
This are the images generated:
- Test image:
cv2
defined rotate function:
ndimage
rotate:
Hopfully it's obvious that I want to make cv2
rotate the image the way ndimage
does - rotate the canvas without loosing original image content.
Does anyone know easy way to do that?