Prev: time related RMS
Next: strange error message
From: Christophe on 14 Sep 2009 00:12 Sorry to bother you but I have the following problem: I have a number of images in RGB-format (not created by Matlab) that I need to convert to CMYK. Is there a simple script to: read image_in_RGB.jpg (or .png, or, ...) convert RGB-to-CMYK and then save image_in_CMYK.jpg Help would be very much appreciated... PS: I only have the "standard" matlab and none of the toolboxes...
From: Bruno Luong on 14 Sep 2009 02:10 The problem is there is no standard formula to convert RGB to CMYK, when you read about the color coding, people keeps telling that CMYK coding should associate with a colorspace of a *specific* device. So to me either they give the formula for this device, but there is no reason a program requires a standalone CMYK image. Anyway, the only output format that supports CMYK is tiff. See help of IMWRITE. I found some "generic" conversion formula between RGB and CMYK (both are 0-1 based): % Black = minimum(1-Red,1-Green,1-Blue) % Cyan = (1-Red-Black)/(1-Black) % Magenta = (1-Green-Black)/(1-Black) % Yellow = (1-Blue-Black)/(1-Black) Up to you to make the conversion and invoke IMWRITE Bruno
From: Dave Robinson on 14 Sep 2009 05:24 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <h8kmnq$b4i$1(a)fred.mathworks.com>... > The problem is there is no standard formula to convert RGB to CMYK, when you read about the color coding, people keeps telling that CMYK coding should associate with a colorspace of a *specific* device. So to me either they give the formula for this device, but there is no reason a program requires a standalone CMYK image. > > Anyway, the only output format that supports CMYK is tiff. See help of IMWRITE. I found some "generic" conversion formula between RGB and CMYK (both are 0-1 based): > > % Black = minimum(1-Red,1-Green,1-Blue) > % Cyan = (1-Red-Black)/(1-Black) > % Magenta = (1-Green-Black)/(1-Black) > % Yellow = (1-Blue-Black)/(1-Black) > > Up to you to make the conversion and invoke IMWRITE > > Bruno As far as I am aware, the primary use for CMYK colour space is in printing, and there the main reasons for its use is that Black (key) ink is much cheaper than the 3 sets of coloured ink that you would need to make up the black component; and also because of the poor colourimetric purity of the inks, equal quantities of CYM usually make a muddy brown and not black, so adding an extra black ink significantly improves the rendition of the picture, when printed. The relationship that Bruno has given is, as he states, only one of the probably infinite number of of transforms. In the print industry they have another parameter which is called the under cover removal UCR) ratio, which represents the amount of black (key) that is to be used to replace equal quantities of CM & Y, thus having no key and having a murky brown image represents a UCR of 0, and the equation that Bruno has provided you is equivelent to a UCR of 1, where the maximum amount of coloured inks are exchanged for black (key). Invariably the value of UCR selected is very ink/printing machine dependent. Hope that helps Regards Dave Robinson
From: ImageAnalyst on 14 Sep 2009 09:07 I completely agree with Bruno and Dave. The only points I might add are 1. A nice collection of "book" formulas for a variety of color space conversions http://www.easyrgb.com/index.php?X=MATH However, I warn you that none of the "book" formulas will work accurately in a real world environment because they just use default values. To get accurate conversions you would have to accurately characterize your imaging pipeline. Sometimes devices (displays, printers, scanners) install their own custom ICC profiles and the operating system is usually aware of those and will use them to try to do its best. You can do even better if you really want to put the effort into it. 2. See Steve's blog where he just talked about this: http://blogs.mathworks.com/steve/2009/09/09/many-steps-needed-for-some-color-space-conversions/ 3. Maybe you should just use Photoshop. Why do you think MATLAB is preferable for this task? I think far, far more people in the printing/publishing industry use Photoshop for RGB/CMYK separations than MATLAB. You can easily program up a macro in Photoshop to do what you say. 4. Who (what program) is going to be the consumer of the cmyk file you write out? If you read it back in with a program that expects jpg images to be RGB then it will look very strange. The program has to be aware that you wrote it out in that color space and not RGB. Just some thoughts........
From: Christophe on 14 Sep 2009 17:37
Thanks guys, but it does not resolve my problem. A bit of background might help: I am a scientist by day and freelance cartoonist by night and my agent has suddenly asked me to provide my cartoons in CMYK instead of RGB as the newspapers are asking for it now (after 10 years without a problem :( ). My problem is that my version of Paint Shop Pro does not do the RGB to CMYK conversion in one operation. It splits the files in 4 files and it is ugly... I thought about using Matlab to do a simple load, save as CMYK, voila... Unfortunately, what I wrote is: cartoon = imread('cartoon1401_colour.tif'); Output_File_Name = 'cartoon1401_colour_CMYK'; image(cartoon); axis off axis equal axis tight print('-dtiff','-cmyk','-r600',Output_File_Name); imfinfo('cartoon1401_colour_CMYK.tif') I was expecting the output to be CMYK as I specify the '-cmyk' flag, but the info from "imfinfo" says it is still RGB and this is what I don't understand: ans = Filename: 'cartoon1401_colour_CMYK.tif' FileModDate: '15-Sep-2009 07:30:14' FileSize: 21467516 Format: 'tif' FormatVersion: [] Width: 4804 Height: 3602 BitDepth: 24 ColorType: 'truecolor' FormatSignature: [73 73 42 0] ByteOrder: 'little-endian' NewSubFileType: 0 BitsPerSample: [8 8 8] Compression: 'PackBits' PhotometricInterpretation: 'RGB' StripOffsets: [3602x1 double] SamplesPerPixel: 3 RowsPerStrip: 1 StripByteCounts: [3602x1 double] XResolution: 600 YResolution: 600 ResolutionUnit: 'Inch' Colormap: [] PlanarConfiguration: 'Chunky' TileWidth: [] TileLength: [] TileOffsets: [] TileByteCounts: [] Orientation: 1 FillOrder: 1 GrayResponseUnit: 0.0100 MaxSampleValue: [255 255 255] MinSampleValue: 0 Thresholding: 1 ImageDescription: 'MATLAB Handle Graphics' Mayby, as you say, I should just bite the bullet and buy photoshop... It is a $1000 though :( |