MPEG-1 压缩 - 生成宏块

发布于 2024-08-13 18:35:10 字数 133 浏览 5 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(2

好听的两个字的网名 2024-08-20 18:35:10

听起来您正在尝试找出将各种 8×8 矩阵收集到单个变量中的最佳方法。有几种方法可以做到这一点(第一个选项是我为您的情况选择的方法):

  • 将数据连接到 3-D 矩阵:

    您可以使用 CAT 函数沿给定维度堆叠相同大小的矩阵。例如,如果变量 L1L2L38×8 亮度矩阵> 和 L4,以下命令会将它们连接成一个 8×8×4 矩阵:

    亮度 = cat(3,L1,L2,L3,L4);
    

    您还可以添加额外的 CbCr 矩阵来创建 8×8×6 矩阵:

    macroBlock = cat(3,L1,L2,L3,L4,Cb,Cr);
    %# 或者...
    MacroBlock = cat(3,亮度,Cb,Cr); %# 使用上面的亮度变量
    

    然后,您可以通过以下方式索引 macroBlock 来访问您需要的任何 8×8 矩阵:

    L2 = 宏块(:,:,2); %# 获取第二个亮度矩阵
    Cb = 宏块(:,:,5); %# 获取Cb矩阵
    
  • 将数据存储在元胞数组中:

    由于所有矩阵的大小都相同,因此上述串联选项可能是最好的。但是,另一种选择(如果您想要存储不同大小、类型或维度的数据,则特别有用)是使用 元胞数组。下面创建一个包含上述矩阵的 1×6 元胞数组:

    macroBlock = {L1 L2 L3 L4 Cb Cr};
    

    然后,您可以通过以下方式索引 macroBlock 来访问您需要的任何 8×8 矩阵:

    L2 = 宏块{2}; %# 获取第二个亮度矩阵
    Cb = 宏块{5}; %# 获取Cb矩阵
    
  • 在结构中存储数据:

    另一种选择是使用结构存储您的8×8矩阵。结构的优点是您可以通过字段名称访问数据,而不必记住索引值。以下是初始化结构的方法:

    macroBlock = struct('L1',L1,'L2',L2,'L3',L3,'L4',L4,'Cb',Cb,'Cr',Cr);
    %# 或者...
    宏块 = struct();
    宏块.L1 = L1;
    宏块.L2 = L2;
    宏块.L3 = L3;
    宏块.L4 = L4;
    宏块.Cb = Cb;
    宏块.Cr = Cr;
    

    上面的两种语法创建了一个具有字段名称 'L1''L2''L3'' 的结构L4''Cb''Cr'。然后,您可以通过以下方式索引 macroBlock 来访问您需要的任何 8×8 矩阵:

    L2 = 宏块.L2; %# 获取第二个亮度矩阵
    Cb = 宏块.Cb; %# 获取Cb矩阵
    

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, and L4, the following will concatenate them into an 8-by-8-by-4 matrix:

    luminance = cat(3,L1,L2,L3,L4);
    

    You could also add the additional Cb and Cr matrices to create an 8-by-8-by-6 matrix:

    macroBlock = cat(3,L1,L2,L3,L4,Cb,Cr);
    %# OR...
    macroBlock = cat(3,luminance,Cb,Cr);  %# Using luminance variable from above
    

    You can then index macroBlock in the following way to access whatever 8-by-8 matrices you need:

    L2 = macroBlock(:,:,2);  %# Get the second luminance matrix
    Cb = macroBlock(:,:,5);  %# Get the Cb matrix
    
  • 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:

    macroBlock = {L1 L2 L3 L4 Cb Cr};
    

    You can then index macroBlock in the following way to access whatever 8-by-8 matrices you need:

    L2 = macroBlock{2};  %# Get the second luminance matrix
    Cb = macroBlock{5};  %# Get the Cb matrix
    
  • 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:

    macroBlock = struct('L1',L1,'L2',L2,'L3',L3,'L4',L4,'Cb',Cb,'Cr',Cr);
    %# OR...
    macroBlock = struct();
    macroBlock.L1 = L1;
    macroBlock.L2 = L2;
    macroBlock.L3 = L3;
    macroBlock.L4 = L4;
    macroBlock.Cb = Cb;
    macroBlock.Cr = Cr;
    

    The two syntaxes above create a structure with field names 'L1', 'L2', 'L3', 'L4', 'Cb', and 'Cr'. You can then index macroBlock in the following way to access whatever 8-by-8 matrices you need:

    L2 = macroBlock.L2;  %# Get the second luminance matrix
    Cb = macroBlock.Cb;  %# Get the Cb matrix
    
悸初 2024-08-20 18:35:10

我没有得到你需要的东西。
将图像划分为这些块的代码?

您应该创建一个矩阵 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.

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