如何旋转yuv420数据?
我需要知道如何将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果图像是 yuv420 平面图像,这就是图像数据的编码方式。
平面表示首先是 y 截面,然后是 U 截面,最后是 V 截面。
考虑图像w的宽度和图像h的高度。
图像的总大小为w*h*3/2
Y部分也称为发光,占据w*h。< /p>
Y 部分中每 2x2 块有一个 U 像素和 V 像素。
接下来是 U 部分,占据 (w/2)*(h/2) 并放置在距图像开头偏移 w*h 的位置。
V 形部分紧随其后,占据 (w/2)*(h/2) 并放置在偏移量 (w*h)+((w*h)/4) 处。
为了将图像旋转 90 度,您实际上需要将此 w*h 数组复制到 h*w 数组,
正如上面的文章中提到的,您只需分别复制上述 3 个 Y、U、V 块即可。
从 Y 部分开始。要复制的第一个像素位于源数组中的 (h-1)*w 处,将其复制到目标数组的 (0,0) 处。第二个像素位于 (h-2)*w 等...
请记住,U 和 V 部分仅为 (w/2)*(h/2)
接下来复制 U 型截面。要复制的第一个像素位于源数组中的 (w*h)+(((h/2)-1)*(w/2)) 处,将其复制到 (h*w)+(0,0)目标数组。第二个像素位于 (w*h)+(((h/2)-2)*(w/2)) 等...
最后复制 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.
The total size of the image is w*h*3/2
The Y section also called luminescence occupies w*h.
there is a U pixel and V pixel for every 2x2 block in Y section.
the U section comes next, occupies (w/2)*(h/2) and is laid at an offset w*h from beginning of the image.
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.
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...
Remember that the U and V sections are only (w/2)*(h/2)
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...
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.
我想它不是 平面 YUV,如果它已经是它,那就很容易了(跳过第一步和最后一步)。你本来打算有 YUV 4:2:0 平面,但我不明白为什么你有困难。
Y
、U
、V
平面。每个块的“颜色”(U
、V
)信息应保持相同。如果您的图像尺寸是 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.
Y
,U
,V
planes separately. The "color" (U
,V
) information for each block then shall be kept the same.This always works fine if your image dimensions are multiple of 4. If not, then take care...
我认为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/