views:

112

answers:

2

I am seeking a method to extract into separate images the Luma (Y), Cb (blue component), Cr (red component), channels of the JPEG images:

I would like results equivalent to this example from Wikipedia.

The output must be calculated directly from the JPEG Start-of-Scan (SOS) data and other data in the JPEG, rather than 'back calculated' from the RGB images output by a decompressor. The purpose of this task is to produce images which represent the 'raw data' as closely as possible.

Are there existing tools which can accomplish this? I am considering throwing together something using Python, PyImage, etc. but I am surprised my search for open source or free tools has come up empty. I am aware there are many libraries which could help, although I am open to becoming aware of more libraries.

For this question, the correct answer would be a tool chain of free and/or open-source tools which can do the job. Tools with source are preferred. These tools can run on any platform, but Linux or Win32 would be immediately useful.

Answer inspired by codelogic

Given the libjpeg implementation, change djpeg.c and wrppm.c.

wrppm.c:

189:    case JCS_RGB:
190: +  case JCS_YCbCr:
191:    /* emit header for raw PPM format */

djpeg.c

560:   case FMT_PPM:
561: +   cinfo.quantize_colors = 0;
562: +   cinfo.out_color_space = JCS_YCbCr;

Obviously, this is quick hack, because I have a private copy where PPM output is always forced to YCbCr, but it works and I thank you, codelogic, for your Stone Code Logic.

+1  A: 

Well the obvious one is libjpg.

rlbond
In fact, therein I found "jpegtran -grayscale" which is half the battle. I just need to extract the Cr, Cb data, and of course I have the source for jpegtran. I might accept this as answer if nothing which can do all 3 channels as-is turns up.
Heath Hunnicutt
+1  A: 

As suggested your best bet would be to use libjpeg directly. Specifically, you might be able to set jpeg_decompress_struct's out_color_space member to be JCS_YCbCr instead of JCS_RGB and read the scanlines as usual. Here's some sample code (GPL).

codelogic
Thank you for leading me by the nose! I made some one-liners to djpeg.c and wrppm.c which allow me to output YCbCr ppm files as you suggested.
Heath Hunnicutt