From sRGB to CMYK and gamma?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

From sRGB to CMYK and gamma?

Post by joew »

Hello,

I have some photos in sRGB color space and I would like to do some manipulations on them (resize, add border, overlay text, etc/pp) and print them on a CMYK printer when done.

In previous versions of IM, I've done it in this way:

Code: Select all

convert Fotos/DSC_0304.JPG \
  -depth 16 -gamma 0.454545 \
  -resample 600x600 \
  -filter lanczos -resize 2000x1000 \
  -do -some -more -operations \
  -gamma 2.2 \
  out.png
This seemed to work fine in older versions of IM. At least, I got no error messages. But with IM-6.7.8 I get this error message:

Code: Select all

$ convert Fotos/DSC_0304.JPG -depth 16 -gamma 0.454545 t.png; display t.png
display: Ignoring incorrect gAMA value .20661 when sRGB is also present `t.png' @ warning/png.c/MagickPNGWarningHandler/1777.
So it seems, I'm doing something really dumb. Any hints how to correctly get from sRGB to something that can be printed on a CMYK printer?
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: From sRGB to CMYK and gamma?

Post by holden »

Try saving as a jpg ot tif instead of a png- seems pngs and cmyk don't mix. One quick link: http://forums.adobe.com/thread/992053
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

Thanks for the hint!

In the meantime, I figured, I should use the "-colorspace XXX" options instead of directly fiddling with gamma. Can anybody confirm this assumption?

In some other thread I found the suggestion to output to jpg, since png supports only rgb. But when I output in jpg, alpha gets lost.

In another example I found the suggestion to call Quantize() after setting the colorspace attribute. What is this good for?

NB: I don't use convert command line tool. Instead, I use the Perl bindings. This is what I am currently doing:

Code: Select all

#! /usr/bin/perl

use Image::Magick;

my $front = Image::Magick->new(density=>600, depth=>16);
$e=$front->Read("Fotos/DSC_0304.JPG"); &e;
$e=$front->Set(colorspace=>"RGB");     &e;

# do some processing here

$e=$front->Set(colorspace=>"CMYK");     &e;
$e=$front->Write("front.jpg"); &e;
Opinions? Suggestions?
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: From sRGB to CMYK and gamma?

Post by holden »

But when I output in jpg, alpha gets lost.
Are you printing onto a transparent surface? Not sure why you would need alpha otherwise- if it is on a transparent surface the printer should have a specific requirement of the filetype you would need. As a side note many printers will take rgb/srgb files because it is so common these days, they can do the necessary conversions on their end. I would contact the printer and see what they recommend.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: From sRGB to CMYK and gamma?

Post by snibgo »

"display: Ignoring incorrect gAMA value .20661 when sRGB is also present `t.png' @ warning/png.c/MagickPNGWarningHandler/1777" isn't an error but a warning. (It says "warning" near the end.)

You can shift gamma if you want, but (depending on the operations) it may be more technically accurate to use "-colorspace RGB" then "-colorspace sRGB".

If you want best-quality CMYK or CMYKA, TIFF is a good format. PNG can't store CMYK. JPG loses information and is only 8-bit, and loses alpha.
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: From sRGB to CMYK and gamma?

Post by GreenKoopa »

joew wrote:I figured, I should use the "-colorspace XXX" options instead of directly fiddling with gamma. Can anybody confirm this assumption?
I would use -colorspace RGB and -colorspace sRGB above, especially since the sRGB gamma isn't quite 2.2 (or even constant). However, the improvement will be small. If you really do need your old method, you can also use -evaluate Pow 2.2
joew wrote:In some other thread I found the suggestion to output to jpg, since png supports only rgb. But when I output in jpg, alpha gets lost.
True, jpg doesn't support alpha. You begin with a jpg; at what point do you create an alpha channel? And why?
joew wrote:In another example I found the suggestion to call Quantize() after setting the colorspace attribute. What is this good for?
Probably not useful here. I think it does something with indexed palettes.
joew wrote:-resample 600x600 -filter lanczos -resize 2000x1000
Why do you -resample before -resize?
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

Are you printing onto a transparent surface? Not sure why you would need alpha otherwise
There are more processing steps to follow. Some of them (like appending images) need the transparency.
If you want best-quality CMYK or CMYKA,
I'm not sure whether I need this conversion at all, since I am printing on my color printer here at home. When I print with gimp, it happily accepts RGB and whatever. But I have no idea what this means to the quality.

Is there a way to print directly from perlmagic?
You begin with a jpg; at what point do you create an alpha channel? And why?
I create alpha when I frame the picture into a roundrectangle frame.
Why do you -resample before -resize?
It's a long time since I've originally wrote this, so I don't remember the details. AFAIR this was needed so the page size would be known, or something.

In fact, on the translation from command line to perlmagic, I dropped the resize, and have not seen any negative effects yet.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: From sRGB to CMYK and gamma?

Post by GreenKoopa »

I would let your printer do the sRGB to CMYK conversion unless you have a reason for doing otherwise. I would also let your printer do the -resample/-resize unless you have a reason. Use -density to set the print size.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: From sRGB to CMYK and gamma?

Post by snibgo »

The printer driver on your computer will translate from sRGB to CMY or CMYK or whatever the physical printer wants. The driver software will probably also ask about the paper stock.

Alternatively, you could use ImageMagick to convert the file to CMY(K) with the profile that is appropriate to your printer and paper. This would substitute for the conversion in the printer driver. You could even calibrate the profile for your exact printer. For most printers, this isn't worth doing -- the driver software does a good job.

EDIT: I cross-posted with GreenKoopa's good advice.
snibgo's IM pages: im.snibgo.com
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

In fact, in the process of translating from command line to perlmagick, I could not make any sense of the Resample() method, so I dropped this step and now use only

Code: Select all

my $image = Image::Magick->new(density => $DPI);
But I think I need the Resize. How would I adopt the output to the size of the actual paper if not with the resize?

As of outputting to the printer: I understand that I could pipe the output to the lpr command. But when printing from gimp, there are lots of things that can be tweaked. Like ignoring borders and such things.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: From sRGB to CMYK and gamma?

Post by GreenKoopa »

You can print from Gimp and still let your printer driver handle the colorspace and sampling conversions.

You know your image's size in pixels, and you know what you want it printed in inches. Divide and set density (pixels per inch).
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

GreenKoopa wrote:You can print from Gimp and still let your printer driver handle the colorspace and sampling conversions.
Printing from gimp is exactly what I want to avoid. No GUI, no dumb knobs to tweak, no opportunities to get those tweaks wrong.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: From sRGB to CMYK and gamma?

Post by GreenKoopa »

joew wrote:Printing from gimp is exactly what I want to avoid.
My mistake. I don't print using Gimp because it frequently gets the position wrong, but maybe this is an incompatibility with my very old printer. How are you printing?
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

GreenKoopa wrote:
joew wrote:Printing from gimp is exactly what I want to avoid.
My mistake. I don't print using Gimp because it frequently gets the position wrong, but maybe this is an incompatibility with my very old printer. How are you printing?
I'm printing with gimp. I tried to print from command line by "lpr foobar.png", but this way the image gets much too big. About 5 or ten times too big.

How do you print?
joew
Posts: 42
Joined: 2012-08-23T01:19:56-07:00
Authentication code: 67789

Re: From sRGB to CMYK and gamma?

Post by joew »

Let's get back to the topic again.

This is what I am currently doing:

Code: Select all

    my $front = Image::Magick->new(density=>$DPI, depth=>16);
    $e=$front->Read($FRONTSIDE_PICTURE); &e;
    $e=$front->Set(colorspace=>"RGB");     &e;
    $e=$front->Resize(geometry=>$FRONT_SIZE, filter=>"Lanczos");  &e;
    $e=$front->Crop(geometry=>$CROP_SIZE);

    # lots of more operations and drawings come here

    $e=$front->Set(colorspace=>"sRGB");     &e;
    $e=$front->Write("front.png"); &e;
When I print the result with gimp, the printout gets mch too dark. So I guess, I'm still doind something wrong. Not only the picture, but all the added drawings get too dark, too.
Post Reply