views:

641

answers:

3

I have been using the below to do a color conversion

    if @image.colorspace == Magick::CMYKColorspace
      # @image.colorspace #=> CMYKColorspace=12
      @image.colorspace = Magick::RGBColorspace
      @image = @image.negate
    end

It works, approximately, but the color luminosity is off. The fact that I need to negate the image leaves a very bad smell.

The documentation mentions using color_profiles, but beyond that I can not find much.

I am now trying

@image = @image.quantize(16777216, Magick::RGBColorspace)

And the colors are better, but still off.

+1  A: 

The incoming files, in this case, do have a profile. I will investigate some more. I got lost with the color profiles (like where do I download them? the ICC site was not much help)

You are not the only one confused; I was too. There are discussions on the ImageMagick site that might be worth siftirng through: Here As far as I understood back then, properly working with profiles is possible when the profile used can be identified (e.g. a monitor profile) or is embedded in the file (which can be done at least for TIFF and JPG in Photoshop, I think). Check e.g. this: Here. Good luck.

Pekka
Getting close, I think. Looks like Image Magick needs to be compiled with `--with-lcms=yes` and the LCMS library installed. When I have a moment I will give this a try.
The Who
+2  A: 

Thanks Pekka, you tipped me off to the answer (+1).

You must have ImageMagick compiled with the Little Color Management System (LCMS) installed. This may already be the case if an installer or package was used. But I was compiling from source. It was as simple as installing LCMS from source and rebuilding ImageMagick (./configure; make; make install).

In ImageMagick the below works well to reproduce accurate color:

convert FILENAME -profile /PATH_TO_PROFILE/sRGB.icm OUT.jpg

So in RMagick I use the below:

if @image.colorspace == Magick::CMYKColorspace
   # Adjust the path as necessary
   @image.color_profile ="/usr/local/share/ImageMagick-6.5.4/config/sRGB.icm"
end

@image.write("out.jpg") { self.quality = 85 }
The Who
+1  A: 

I found that The Who's command line solution worked beautifully, but the RMagick solution did not work for me.

To get it to work in RMagick, I instead I had to use the Magick::Image#add_format method, which, according to the docs, will allow you to specify an source and destination profile. It looks like this:

if img.colorspace == Magick::CMYKColorspace
  img.add_profile(RGB_COLOR_PROFILE)
end 
Mike Dotterer