Page 1 of 1

JPEG encoding w/ JFIF encoding

Posted: 2017-03-14T14:21:26-07:00
by Hitachi1961
OS/Platform: OSX 10.12.3
IM Version: stable 7.0.5-0

Does imagemagick implement/provide an api or any helpers to use standard JFIF encoding when compressing/encoding a JPEG image? Based on this wikipedia article my understanding of the steps involved are the following:
  1. Optionally convert the colors in the image from RGB to YCBCR
  2. Optionally reduce the resolution of chroma data by a factor of 2 or 3
  3. Split up the image into blocks of 8x8 pixels and apply DCT-II on each pixel to get DCT coefficients
  4. Quantize DCT coefficients
  5. Compress quantized values using some variant of Huffmans encoding
I feel like I'm trying to "reinvent the wheel" and maybe theres something already built into imagemagick encoding process to help with this. Some of the steps are somewhat still vague to me, (for example the Huffman encoding step) so any clarification would also help. Ideally I would like to be able to perform each of the steps at a high level and have access to the data during each step, for example:

Code: Select all

ycbcr_values[] = imagetorcbcr('my image.jpeg');
ycbcr_values[] = reducechroma(ycbcr_values, 3);
blocks[][] = pixelstoblocks(ycbcr_values, 8, 8);
dct_blocks[][] = dct(blocks);
quantized_blocks[][] = quantize(dct_blocks);
image = writeimage('out image.jpeg', quantized_blocks);
 

Re: JPEG encoding w/ JFIF encoding

Posted: 2017-03-14T14:49:26-07:00
by fmw42

Re: JPEG encoding w/ JFIF encoding

Posted: 2017-03-14T14:52:56-07:00
by snibgo
IM does all that work for you. Just write to an output file with extension ".jpg" or ".jpeg".

But it doesn't give you access to data during each step.