如何旋转yuv420数据?

发布于 2024-09-07 01:23:32 字数 101 浏览 4 评论 0原文

我需要知道如何将 yuv420p 格式的图像旋转 90 度。将其转换为 rgb、旋转并再次重新转换为 yuv 的选项是不可行的。即使是算法也会有所帮助。

问候, 阿尼鲁德。

I need to know how to rotate an image, which is in yuv420p format by 90 degrees. The option of converting this to rgb, rotating and again reconverting to yuv is not feasible. Even an algorithm would help.

Regards,
Anirudh.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人事已非 2024-09-14 01:23:32

如果图像是 yuv420 平面图像,这就是图像数据的编码方式。
平面表示首先是 y 截面,然后是 U 截面,最后是 V 截面。

考虑图像w的宽度和图像h的高度。

  1. 图像的总大小为w*h*3/2

  2. Y部分也称为发光,占据w*h。< /p>

  3. Y 部分中每 2x2 块有一个 U 像素和 V 像素。

  4. 接下来是 U 部分,占据 (w/2)*(h/2) 并放置在距图像开头偏移 w*h 的位置。

  5. V 形部分紧随其后,占据 (w/2)*(h/2) 并放置在偏移量 (w*h)+((w*h)/4) 处。

为了将图像旋转 90 度,您实际上需要将此 w*h 数组复制到 h*w 数组,

正如上面的文章中提到的,您只需分别复制上述 3 个 Y、U、V 块即可。

  1. 从 Y 部分开始。要复制的第一个像素位于源数组中的 (h-1)*w 处,将其复制到目标数组的 (0,0) 处。第二个像素位于 (h-2)*w 等...

  2. 请记住,U 和 V 部分仅为 (w/2)*(h/2)

  3. 接下来复制 U 型截面。要复制的第一个像素位于源数组中的 (w*h)+(((h/2)-1)*(w/2)) 处,将其复制到 (h*w)+(0,0)目标数组。第二个像素位于 (w*h)+(((h/2)-2)*(w/2)) 等...

  4. 最后复制 V 部分。要复制的第一个像素位于源数组中的 ((w*h)+(w*h/4))+(((h/2)-1)*(w/2)) 处,将其复制到 (h目标数组中的 *w)+(w*h/4)+(0,0)。第二个像素位于 ((w*h)+(w*h/4))+(((h/2)-2)*(w/2)) 依此类推...

在此获得的目标数组way 包含 90 度旋转图像。

In case the image is yuv420 planar, this is how the image data is encoded.
Planar meaning the y section is first, followed by U section and then with V section.

Considering the width of the image w, and height of the image h.

  1. The total size of the image is w*h*3/2

  2. The Y section also called luminescence occupies w*h.

  3. there is a U pixel and V pixel for every 2x2 block in Y section.

  4. the U section comes next, occupies (w/2)*(h/2) and is laid at an offset w*h from beginning of the image.

  5. the V section follows, occupies (w/2)*(h/2) and is laid at an offset of (w*h)+((w*h)/4).

In order to rotate the image by 90 degrees, you essentially copy this w*h array to an array of h*w

As mentioned in above post, you simply need to copy each of the 3 above Y, U, V blocks separately.

  1. Start with the Y section. The 1st pixel to be copied is at (h-1)*w in Source Array, copy this to (0,0) of destination array. The 2nd pixel is at (h-2)*w and so on...

  2. Remember that the U and V sections are only (w/2)*(h/2)

  3. Next copy the U section. The first pixel to be copied is at (w*h)+(((h/2)-1)*(w/2)) in Source Array, copy this to (h*w)+(0,0) in the Destination Array. The 2nd pixel is at (w*h)+(((h/2)-2)*(w/2)) and so on...

  4. Finally copy the V section. The first pixel to be copied is at ((w*h)+(w*h/4))+(((h/2)-1)*(w/2)) in Source Array, copy this to (h*w)+(w*h/4)+(0,0) in the Destination Array. The 2nd pixel is at ((w*h)+(w*h/4))+(((h/2)-2)*(w/2)) and so on...

The Destination Array obtained in this way contains the 90 degree rotated image.

<逆流佳人身旁 2024-09-14 01:23:32

我想它不是 平面 YUV,如果它已经是它,那就很容易了(跳过第一步和最后一步)。你本来打算有 YUV 4:2:0 平面,但我不明白为什么你有困难。

  1. 首先将其转换为平面:为平面分配空间,并根据 打包的 YUV 格式。
  2. 分别旋转 YUV 平面。每个块的“颜色”(UV)信息应保持相同。
  3. 重新组合平面以重新获得您一开始就有的正确的打包的 YUV

如果您的图像尺寸是 4 的倍数,这总是可以正常工作。如果不是,那么请小心...

I suppose it is not planar YUV, if it is it already it's quite easy (skip first and last steps). You meant to have YUV 4:2:0 planar, but then I do not understand why you have difficulties.

  1. convert it to a planar first: allocate space for planes and put bytes at right places according to the packed YUV format you have.
  2. rotate the Y, U, V planes separately. The "color" (U, V) information for each block then shall be kept the same.
  3. recombine the planes to reobtain the right packed YUV you had at the beginning

This always works fine if your image dimensions are multiple of 4. If not, then take care...

淑女气质 2024-09-14 01:23:32

我认为YUV420p确实是平面的。

尝试查看 AviSynth 的源代码。 Turn(旋转)函数在turn.cpp和turnfunc.cpp

http://www.avisynth.org/

I think YUV420p is indeed planar.

Try and take a look at AviSynth's source code. The turn (rotate) functions are in turn.cpp and turnfunc.cpp

http://www.avisynth.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文