문제

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?

도움이 되었습니까?

해결책

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.

im = jpeg_read(image);
% Pull image information - Lum, Cb, Cr
lum = im.coef_arrays{im.comp_info(1).component_id};
cb = im.coef_arrays{im.comp_info(2).component_id};
cr = im.coef_arrays{im.comp_info(3).component_id};
% Pull quantization arrays
lqtable = im.quant_tables{im.comp_info(1).quant_tbl_no};
cqtable = im.quant_tables{im.comp_info(2).quant_tbl_no};
% Quantize above two sets of information
lqcof = quantize(lum,lum_qtable);
bqcof = quantize(cb,cho_qtable);
rqcof = quantize(cr,cho_qtable);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top