MPEG-1 压缩 - 生成宏块
我在 MPEG-1 压缩中遇到了一个基本问题。我必须在图像中生成宏块。宏块由 16 x 16 像素组成 - 其中 4 x 8x8 是亮度,1 x 8x8 是 Cb,1 x 8x8 Cr。在 MATLAB 中,我想生成一个包含此的单元矩阵。有什么建议吗?
I'm stuck with a basic problem in my MPEG-1 compression. I have to produce macroblocks within a image. A macroblock consists of 16 x 16 pixels - where 4 x 8x8 is luminance, 1 x 8x8 is Cb and 1 x 8x8 Cr. In MATLAB I want to produce a cell matrix containing this. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您正在尝试找出将各种 8×8 矩阵收集到单个变量中的最佳方法。有几种方法可以做到这一点(第一个选项是我为您的情况选择的方法):
将数据连接到 3-D 矩阵:
您可以使用 CAT 函数沿给定维度堆叠相同大小的矩阵。例如,如果变量
L1
、L2
、L3
8×8 亮度矩阵> 和L4
,以下命令会将它们连接成一个 8×8×4 矩阵:您还可以添加额外的
Cb
和Cr
矩阵来创建 8×8×6 矩阵:然后,您可以通过以下方式索引
macroBlock
来访问您需要的任何 8×8 矩阵:将数据存储在元胞数组中:
由于所有矩阵的大小都相同,因此上述串联选项可能是最好的。但是,另一种选择(如果您想要存储不同大小、类型或维度的数据,则特别有用)是使用 元胞数组。下面创建一个包含上述矩阵的 1×6 元胞数组:
然后,您可以通过以下方式索引
macroBlock
来访问您需要的任何 8×8 矩阵:在结构中存储数据:
另一种选择是使用结构存储您的8×8矩阵。结构的优点是您可以通过字段名称访问数据,而不必记住索引值。以下是初始化结构的方法:
上面的两种语法创建了一个具有字段名称
'L1'
、'L2'
、'L3'
、' 的结构L4'
、'Cb'
和'Cr'
。然后,您可以通过以下方式索引macroBlock
来访问您需要的任何 8×8 矩阵:It sounds like you're trying to figure out the best way to collect your various 8-by-8 matrices into a single variable. There are a few ways you can do this (with the first option being the one I would choose for your case):
Concatenating data into a 3-D matrix:
You can use the CAT function to stack matrices of the same size along a given dimension. For example, if you have your 4 8-by-8 luminance matrices in the variables
L1
,L2
,L3
, andL4
, the following will concatenate them into an 8-by-8-by-4 matrix:You could also add the additional
Cb
andCr
matrices to create an 8-by-8-by-6 matrix:You can then index
macroBlock
in the following way to access whatever 8-by-8 matrices you need:Storing data in a cell array:
Since all of your matrices are the same size, the above concatenation option is probably best. However, another option (which is especially useful if you want to store data of varying size, type, or dimension) is to use cell arrays. The following creates a 1-by-6 cell array containing the above matrices:
You can then index
macroBlock
in the following way to access whatever 8-by-8 matrices you need:Storing data in a structure:
Another option is to use a structure to store your 8-by-8 matrices. A structure has the benefit that you can access data by field name as opposed to having to remember an index value. Here's how you would initialize a structure:
The two syntaxes above create a structure with field names
'L1'
,'L2'
,'L3'
,'L4'
,'Cb'
, and'Cr'
. You can then indexmacroBlock
in the following way to access whatever 8-by-8 matrices you need:我没有得到你需要的东西。
将图像划分为这些块的代码?
您应该创建一个矩阵 I(i, j, m ,n),其中 m、n 代表图像的第 n 个和第 m 个 8X8 块,i、j 指块内的特定像素。
I didn't get what you need.
A code which partition the image into those blocks?
What you should create is a matrix I(i, j, m ,n) where m, n stands for the n'th and m'th 8X8 block of the image and i, j refers to a specific pixel within the block.