任意度数的 Numpy 矩阵旋转 [英] Numpy matrix rotation for any degrees

查看:443
本文介绍了任意度数的 Numpy 矩阵旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试找到一种方法,在我的矩阵上应用任意度数的矩阵旋转,该矩阵包含三个波段(如 RGB)但值大于 (0-255).

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).

这是我的数据的一个例子,它的形状是 (100, 100, 3):

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]]

我找到了一个函数 scipy.misc.imrotate(image_array, 20) 但问题是这个函数将我的数据重新缩放到范围 (0-255),因此我丢失了原始矩阵的信息.是否有一个函数可以在不重新缩放数据的情况下完成与前一个相同的工作?

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 ?

推荐答案

您是否尝试过 scipy.ndimage.interpolation 中的 rotate 功能?

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.

这篇关于任意度数的 Numpy 矩阵旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆