From 17e0cc3fd801c1ed1f69333205d2206e97f81280 Mon Sep 17 00:00:00 2001 From: linarphy Date: Tue, 9 May 2023 14:32:03 +0200 Subject: [PATCH] Add rotate function use OpenCV for fastest rotation --- utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils.py b/utils.py index fc9f457..47e61e7 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ from astropy.io.fits import open +import cv2 import numpy as np global_i = 0 @@ -202,3 +203,11 @@ def last_consecutive( list_ ): else: # if inside the consecutive list and last element, every element is consecutive break 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 )