Decompress (color) JPG struct read via Phil Sallee's jpg toolbox to spatial domain
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I am a tiny bit stuck with decompressing a 3 channel color jpg into spatial domain. To directly access the jpg's DCT coefficients and quanitsation tables I've opened the jpg file via Phil Sallee's jpg toolbox's jpeg_read() function as follows and tried decompressing it as follows:
addpath('jpeg_toolbox-2/');
path = '/data/test.jpg';
img = jpeg_read(path);
Lum = img.coef_arrays{img.comp_info(1).component_id};
ChromCr = img.coef_arrays{img.comp_info(2).component_id};
ChromCb = img.coef_arrays{img.comp_info(3).component_id};
Lum_quant_table = img.quant_tables{img.comp_info(1).quant_tbl_no};
Chrom_quant_table = img.quant_tables{img.comp_info(2).quant_tbl_no};
fun = @(x)x.data .*Lum_quant_table;
lum_spatial = blockproc(Lum,[8 8],fun);
fun2 = @(x)x.data .*Chrom_quant_table;
cr_spatial = blockproc(ChromCr,[8 8],fun2);
cb_spatial = blockproc(ChromCb,[8 8],fun2);
fun3=@(x)idct2(x.data);
lum_spatialf = blockproc(lum_spatial,[8 8],fun3);
cr_spatialf = blockproc(cr_spatial,[8 8],fun3);
cb_spatialf = blockproc(cb_spatial,[8 8],fun3);
f = cat(3, lum_spatialf, cr_spatialf, cb_spatialf);
f = ycbcr2rgb(f);
imshow(f);
save('data/test4.mat','f', '-v6');
(The first part - extracting the coefficents and tables - is taken from the book Steganography in Digital Media: Principles, Algorithms, and Applications.)
It seems like I am missing something since the decompression does not quite look right...
For grayscale images I manage to do the decompression:
img = jpeg_read(path);
fun = @(x)x.data .*img.quant_tables{1};
spatial = blockproc(img.coef_arrays{1},[8 8],fun);
fun=@(x)idct2(x.data);
f = blockproc(spatial,[8 8],fun);
imshow(f);
save('data/test8.mat','f', '-v6');
but for color images I don't get it to work.
Thank you very much in advance!
0 Commenti
Risposte (1)
Fady Samann
il 24 Ago 2020
Modificato: Fady Samann
il 24 Ago 2020
You can not move back and forth between DCT and RGB without loss, due to quantization, rounding, and truncation. The reconstracted image will in general differ from the original one.
I tried your codes and both of them did not give something right.
According to the book you mentioned, you are missing rounding and truncation after the IDCT step. Check pages 27 and 28.
Moreover, the conversion RGB <--> YCrCb also add to the loss, check the project report linked below.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!