问题
I try to find a way to apply a matrix rotation of any degrees on my matrix that contains three bands like RGB but values are bigger than (0-255).
It is an example of my data its shape is (100, 100, 3):
[[ 847.5 877. 886. ... 821.5 856.5 898. ]
[ 850. 883. 969.5 ... 885. 878.5 947.5]
[ 982. 968.5 927.5 ... 909.5 958. 1037. ]
...
[ 912. 827. 893. ... 1335. 1180. 1131. ]
[ 954. 855.5 882. ... 1252. 1266. 1335. ]
[ 984. 916. 930. ... 1080.5 1278. 1385.5]]
I found a function scipy.misc.imrotate(image_array, 20)
but the problem is this function rescales my data to the range (0-255), thus I loose information of my original matrix. Is there a function that does the same job as the previous one without rescaling data ?
回答1:
Have you tried rotate
function from scipy.ndimage.interpolation
?
import numpy as np
from scipy.ndimage.interpolation import rotate
x = np.random.randint(800, 1000, size=[100, 100, 3])
rotated = rotate(x, angle=45)
It does rotate matrix without scaling the values.
回答2:
You might want to try open CV's warpAffine(). It allows for rotation and translation of the image.
Depending on your choice of interpolation method you might have some changes to your values thoug.
来源:https://stackoverflow.com/questions/53171057/numpy-matrix-rotation-for-any-degrees