如何使用 Sallee 的代码从 MATLAB 查找量化系数?
首先,我承认这是一个家庭作业问题。然而,我似乎被困住了。我需要使用 Phil Sallee 的 JPEG Toolbox 从 jpeg 图像中获取所有量化系数(链接位于表格底部“更新”标题下)(我将构建一个直方图,但是一旦我可以获得我需要的数据,我就可以处理该部分)。我有一个大小约为 5 MB 的 JPEG 图像,当我通过 Sallee 的代码运行它时取回此数据:
image_width: 3000
image_height: 4000
image_components: 3
image_color_space: 2
jpeg_components: 3
jpeg_color_space: 3
comments: {}
coef_arrays: {[4000x3000 double] [2000x3000 double] [2000x3000 double]}
quant_tables: {[8x8 double] [8x8 double]}
ac_huff_tables: [1x2 struct]
dc_huff_tables: [1x2 struct]
optimize_coding: 0
comp_info: [1x3 struct]
progressive_mode: 0
如何从该图像中获取量化系数?起初,我尝试了这样的方法,只是吐出系数,这样我就可以看到我正在处理的内容:
pic = jpeg_read(image)
img_coef = pic.quant_tables{pic.comp_info(1).quant_tbl_no}
img_coef = pic.quant_tables{pic.comp_info(2).quant_tbl_no}
img_coef
运行两次,因为 quant_tables
数据有两个元素上面点。然而,对于如此大的图像来说,这似乎是非常少量的系数。在这方面比我更有知识的人可以为我指出正确的方向吗?在哪里/如何从 jpeg 图像中提取量化系数?
First, I admit that this is a homework question. However, I seem to be stuck. I need to get all quantized coefficients from a jpeg image using Phil Sallee's JPEG Toolbox (link listed at the bottom of the table under an "update" heading)(I'll be building a histogram, but that part I can handle once I can get to the data I need). I have a JPEG image that is about 5 MB in size and get back this data when I run it through Sallee's code:
image_width: 3000
image_height: 4000
image_components: 3
image_color_space: 2
jpeg_components: 3
jpeg_color_space: 3
comments: {}
coef_arrays: {[4000x3000 double] [2000x3000 double] [2000x3000 double]}
quant_tables: {[8x8 double] [8x8 double]}
ac_huff_tables: [1x2 struct]
dc_huff_tables: [1x2 struct]
optimize_coding: 0
comp_info: [1x3 struct]
progressive_mode: 0
How do I get the quantized coefficients from this image? At first I tried something like this to just spit out the coefficients so I could see what I was dealing with:
pic = jpeg_read(image)
img_coef = pic.quant_tables{pic.comp_info(1).quant_tbl_no}
img_coef = pic.quant_tables{pic.comp_info(2).quant_tbl_no}
img_coef
is run twice because there are two elements to the quant_tables
data point above. However, this seems like a very low amount of coefficients for such a large image. Can someone more knowledgeable than me in this regard point me in the right direction? Where/how do I pull the quantized coefficients from a jpeg image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您已经获得了所需的信息。从您提供的数据来看,JPEG 工具包似乎对系数进行了解码并将其加载到“coef_arrays”中。您的图像具有水平二次采样;这通过颜色系数阵列是亮度宽度的一半来指示。 3个数组代表(Y,Cr,Cb)。有 2 个量化表,因为一个用于 Y 分量,另一个用于 Cr 和 Cb 分量。为了对系数进行反量化,您需要将 quant_tables[] 数组的正确元素与每个系数相乘。例如,系数数组的元素 [8, 10] 应乘以 quant_table 的元素 [0,2]。 8x8 量化数组在每组 8x8 系数中重复使用。通常这些是呈之字形的顺序,但看起来您的工具包已将其布置得像完整的图像一样。
It appears that you have the information you need. From the data you've provided, it looks like the JPEG toolkit decodes the coefficients and loads them into the "coef_arrays". Your image has horizontal subsampling; this is indicated by the color coefficient arrays being half the width of the luminance. The 3 arrays represent (Y, Cr, Cb). There are 2 quantization tables because one is for the Y component and the other is for the Cr and Cb components. In order to de-quantize the coefficients, you will need to multiply the correct element of the quant_tables[] array with each coefficient. For example, element [8, 10] of your coefficients array should be multiplied by element [0,2] of your quant_table. The 8x8 quantization array gets re-used across every 8x8 set of coefficients. Normally these are in zig-zag order, but it appears that your toolkit has laid it out like a complete image.
这将打开一个文件,提取亮度、Cr 和 Cb 数组以及两个量化数组。然后它将亮度、Cr 和 Cb 量化为它们自己的变量。
This will open a file, pull off the luminance, Cr and Cb arrays, and the two quantization arrays. It will then quantize luminance, Cr and Cb into their own variables.