-->

Using existing tools, how can I extract into separ

2020-07-22 18:58发布

问题:

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

  • Seattle Police Department image #1
  • Seattle Police Department image #2
  • Seattle Police Department image #3

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:

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).



回答2:

Well the obvious one is libjpg.