Add rotate function

use OpenCV for fastest rotation
This commit is contained in:
linarphy 2023-05-09 14:32:03 +02:00
parent a240bf83e8
commit 17e0cc3fd8
No known key found for this signature in database
GPG key ID: 3D4AAAC3AD16E79C

View file

@ -1,4 +1,5 @@
from astropy.io.fits import open from astropy.io.fits import open
import cv2
import numpy as np import numpy as np
global_i = 0 global_i = 0
@ -202,3 +203,11 @@ def last_consecutive( list_ ):
else: # if inside the consecutive list and last element, every element is consecutive else: # if inside the consecutive list and last element, every element is consecutive
break break
return i return i
def rotate( image , angle ):
"""
rotate the following image by the given angle
"""
height , width = image.shape[ : 2 ]
cX , cY = ( width // 2 , height // 2 )
matrix = cv2.getRotationMatrix2D( ( cX , cY ) , angle , 1 )
return cv2.warpAffine( image , matrix , ( width , height ) , flags = cv2.INTER_LINEAR )