将2D像素阵列旋转90度 [英] Rotating a 2D pixel array by 90 degrees

查看:280
本文介绍了将2D像素阵列旋转90度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像的像素数据数组。我得到的图像已经旋转到270度。所以我想再次旋转90度,以获得正确的图像。我尝试了一个转置算法,通过将 data [x] [y] 更改为 data [y] [x] ,但我不认为这是正确的方式。

解决方案

这可以在不使用任何额外空间的情况下完成,所以称为就地矩阵变换(不完全相同)。





如果图片是方形的, b

>


  • 如果图片不是正方形




    • 对于非正方形矩阵,算法更复杂。 1980年之前的许多算法可以被描述为循环周期算法。也就是说,它们循环遍历周期,在周期中将数据从一个位置移动到下一个位置。以伪码形式:





  • I have an array of pixel data for an image. The image I am getting is already rotated to 270 degrees. So I am trying to rotate it again by 90 degrees to have the correct image. I've tried a transpose algorithm, by changing data[x][y] to data[y][x], but I don't think that's the correct way. Can anyone guide me what can I do to have it rotated?

    解决方案

    This can be done without using any extra space, so called In-place matrix transposition (not exact the same). Remember to do some mirroring after the transposition.

    1. If the image is square

    2. If the image is not square

      • For non-square matrices, the algorithms are more complicated. Many of the algorithms prior to 1980 could be described as "follow-the-cycles" algorithms. That is, they loop over the cycles, moving the data from one location to the next in the cycle. In pseudocode form:

    这篇关于将2D像素阵列旋转90度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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