将 2D 像素阵列旋转 90 度

Rotating a 2D pixel array by 90 degrees(将 2D 像素阵列旋转 90 度)
本文介绍了将 2D 像素阵列旋转 90 度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个图像的像素数据数组.我得到的图像已经旋转到 270 度.所以我试图将它再次旋转 90 度以获得正确的图像.我尝试了一种转置算法,将 data[x][y] 更改为 data[y][x],但我认为这不是正确的方法.谁能指导我如何旋转它?

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. 如果图片是方形的

  1. If the image is square

如果图像不是方形的

  • 对于非方阵,算法更为复杂.1980 年之前的许多算法都可以被描述为follow-the-cycles"算法.也就是说,它们在循环中循环,将数据从循环中的一个位置移动到下一个位置.以伪代码形式:

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)