sRGB to RGB colorspace / profile not working?

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?".
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I've got a web application that generates a designed image on the server. The designed image will ultimately get printed onto a physical object so we need the colorspace from the front-end (web browser) to match the generated image (ImageMagick). It looks like IM prefers sRGB colorspace wherever possible, but I have the front-end providing hex values in the RGB colorspace.

I've tried manually setting colorspace & profiles and still do not see results that line up with the RGB values.

What am I missing?

Gist of my code is here: https://gist.github.com/mackermedia/544 ... bff635459b
The application is written in Ruby and uses the [mini_magick gem[https://github.com/minimagick/minimagick]

(Another strange thing is the 2nd and 3rd images produce different colors where the operation is only setting background transparent & doing extent).

Please help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

IM can work with hex values. That should not be a problem. But is this really an Imagemagick issue? Looks more like your other application's issue.

Can you provide an input and output image for us to review the colorspace, etc. You can upload your images to some free image hosting service such as dropbox (public folder) and put links here to them.

Can you explain the functionality of your code or give us an ImageMagick command line equivalent so we can test independently?

Have you read http://www.imagemagick.org/Usage/formats/#profiles
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I've update the gist to include links to public dropbox files. It also shows what happens when just using "#ff0000". The identify command always shows colorspace = sRGB no matter what I do. I'm thinking it could be that the meta-data is just stale or something.

I'm working on figuring out how to debug and output the corresponding IM command line commands via the Ruby gem I'm using.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I've now updated the gist to include the IM commands that are run.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

Please explain what you are trying to achieve in a descriptive way.

Hex colors should not affect any change in colorspace. All I see is a red image. What are you trying to do to a red image?

Note that PNG only supports sRGB and no other colorspace such as CMYK. The IM verbose data will show you in the PNG info section what PNG parameters and profile is being used. But I do not think you can do much with profiles other than trying to switch to different sRGB profiles.

Try your experiments with jpg for output or perhaps tiff.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I've updated it now to show with the Orange color that we identified the bug with (specified as "rgb(239, 152, 58)"). I also included a link at the bottom showing the digital color meter values.

What I am trying to do is generate an image based on user selected values. They can choose a custom color (any RGB value) and do some other operations (add image, add text, position image, rotate image, etc). We noticed that the color on the web front-end (which is using RGB) does not line up correctly with the server generated image. We then discovered that the server generated image was using the sRGB colorspace instead of RGB.

My code is just an example showing similar image operations (minus image & text manipulation) that are used server side. It starts with a big transparent blank image, resizes it to the correct size for the user chosen object, draws a big rectangle with user specified color. Then there are some more operations to overly a print template, add a unique ID, and then convert to TIFF for the image to be printed.

Is it possible that it is because I'm starting with a blank (transparent) png as my starting point (which doesn't accept RGB) and not a TIFF file?

Does this explanation help?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

What version of Imagemagick are you using? There was a time when specifying RGB meant sRGB, but was later corrected so that specifying sRGB was correctly sRGB and RGB was linear RGB. But not all image formats support linear RGB.

see
viewtopic.php?f=4&t=21269
http://www.imagemagick.org/script/forma ... colorspace

I suspect you need to specify sRGB for your colorspace when using PNG or generally other image formats such as jpg and tiff.

IM internally will support linear RGB, but most image formats that you can use to output will not recognize it. You would need to use proper profiles with jpg or tiff to get something like Adobe RGB rather than sRGB.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I'm using: Version: ImageMagick 6.8.7-7 Q16 x86_64 2013-12-17 http://www.imagemagick.org

I've tried the experiment again this time starting with a TIFF image that has:
Profiles:
Profile-8bim: 3454 bytes
Profile-icc: 3144 bytes
IEC 61966-2.1 Default RGB colour space - sRGB
Profile-tiff:37724: 496 bytes
Profile-xmp: 14095 bytes

The results now with TIFF files can be seen at:
https://dl.dropboxusercontent.com/u/657 ... -color.tif
&
https://dl.dropboxusercontent.com/u/657 ... mplate.tif

It looks like the file is still using sRGB as I'm seeing sRGB values of 239, 152, 58 and RGB values of 233, 133, 45
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

I've tried it again starting with a TIFF file with profile:
Profiles:
Profile-8bim: 6610 bytes
Profile-icc: 1960 bytes
Generic RGB Profile
Profile-xmp: 14969 bytes

After I draw the colored rectangle with command:
mogrify -colorspace RGB -fill rgb\(239,\ 152,\ 58\) -draw rectangle\ 0,0\ 5000,5000 /var/folders/kl/r23pycrx641dlnk667473v6r0000gn/T/mini_magick20140204-21383-1e2arxg.tif

The resultant image is still showing sRGB 239, 152, 58 and not RGB with profile now at:
Profiles:
Profile-8bim: 6610 bytes
Profile-xmp: 14969 bytes
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

Mogrify is not the right command to use. You should use convert.


convert -size 100x100 xc:"rgb(239,152,59)" -profile /Users/fred/images/Profiles/sRGB.icc -profile /Users/fred/images/Profiles/GenericRGBProfile.icc -depth 8 test.tif

identify -verbose test.tif

Code: Select all

Image: test.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 100x100+0+0
  Units: PixelsPerInch
  Type: Palette
  Base type: TrueColor
  Endianess: LSB
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 233 (0.913725)
      max: 233 (0.913725)
      mean: 233 (0.913725)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 134 (0.52549)
      max: 134 (0.52549)
      mean: 134 (0.52549)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 46 (0.180392)
      max: 46 (0.180392)
      mean: 46 (0.180392)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Image statistics:
    Overall:
      min: 46 (0.180392)
      max: 233 (0.913725)
      mean: 137.667 (0.539869)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Colors: 1
  Histogram:
     10000: (233,134, 46) #E9862E srgb(233,134,46)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 100x100+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: TopLeft
  Properties:
    date:create: 2014-02-04T13:17:26-08:00
    date:modify: 2014-02-04T13:17:26-08:00
    icc:copyright: Copyright 2007 Apple Inc., all rights reserved.
    icc:description: Generic RGB Profile
    icc:manufacturer: Generic RGB Profile
    icc:model: Generic RGB Profile
    signature: eae035403546fb560619e5a865731ff9110a3e6c9749c3a074a126029bb38f87
    tiff:document: test.tif
    tiff:endian: lsb
    tiff:photometric: RGB
    tiff:rows-per-strip: 27
  Profiles:
    Profile-icc: 1328 bytes
  Artifacts:
    filename: test.tif
    verbose: true
  Tainted: False
  Filesize: 31.7KB
  Number pixels: 10K
  Pixels per second: 10EB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.8-4 Q16 x86_64 2014-01-29 http://www.imagemagick.org
The colorspace will be shown as sRGB, but the profile takes care of the conversion to Generic RGB, because tiff does not properly support colorspace=RGB except through profiles. Note also that the color values are different from those specified.


Similarly for jpg output

convert -size 100x100 xc:"rgb(239,152,59)" -profile /Users/fred/images/Profiles/sRGB.icc -profile /Users/fred/images/Profiles/GenericRGBProfile.icc -depth 8 test.jpg

identify -verbose test.tif

Code: Select all

Image: test.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 100x100+0+0
  Units: Undefined
  Type: Palette
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 234 (0.917647)
      max: 234 (0.917647)
      mean: 234 (0.917647)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 134 (0.52549)
      max: 134 (0.52549)
      mean: 134 (0.52549)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 46 (0.180392)
      max: 46 (0.180392)
      mean: 46 (0.180392)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Image statistics:
    Overall:
      min: 46 (0.180392)
      max: 234 (0.917647)
      mean: 138 (0.541176)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Colors: 1
  Histogram:
     10000: (234,134, 46) #EA862E srgb(234,134,46)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 100x100+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 92
  Orientation: Undefined
  Properties:
    date:create: 2014-02-04T13:17:26-08:00
    date:modify: 2014-02-04T13:17:26-08:00
    icc:copyright: Copyright 2007 Apple Inc., all rights reserved.
    icc:description: Generic RGB Profile
    icc:manufacturer: Generic RGB Profile
    icc:model: Generic RGB Profile
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: 24f2a5d856528207c33a11fed1f4c19ec4d7f3800ecedbdb504bbdfa791a7b21
  Profiles:
    Profile-icc: 1328 bytes
  Artifacts:
    filename: test.jpg
    verbose: true
  Tainted: False
  Filesize: 1.71KB
  Number pixels: 10K
  Pixels per second: 10EB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.8-4 Q16 x86_64 2014-01-29 http://www.imagemagick.org

Note also that in IM rgb(...) is really srgb(...). You are specifying sRGB colors and not linear colors when using hex or rgb(...) notation.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

fmw42 I really appreciate all your help here as this is really critical to my application.

My issue is that when the user is given a custom color input allowing them to specify RGB values in decimal fashion (255, 255, 255) I am expecting to generate an image with those exact color values output.

It's interesting that you mentioned that TIFF only supports RGB when using profile files. Could you possible make those files available somewhere? I couldn't find them.

Also, if using hex "#ef983a" and "rgb(239, 152, 58)" are actually specifying values in sRGB what would you recommend that I use to use actual RGB?

This so sooooo confusing. I wish ImageMagick would just respect when I tell it to use colorspace RGB!

I'll work on using convert instead of mogrify, however the ruby wrapper that I'm using (mini_magick) uses mogrify under the hood for all of its operations.

I'm really running out of ideas here.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

fmw42: I was able to find the profile files here: https://github.com/Erls-Corporation/ope ... s/Profiles

I used your same command, and the result is the exact same colors I'm getting. Looking at your verbose output, I see that the red value shown is 233, blue 134, and green 46. This is the problem I'm hoping to solve. How can I get the red to be 239, blue 152, and green 58 so that the output result color matches what the user inputs as normal RGB?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

mackermedia wrote:fmw42: I was able to find the profile files here: https://github.com/Erls-Corporation/ope ... s/Profiles

I used your same command, and the result is the exact same colors I'm getting. Looking at your verbose output, I see that the red value shown is 233, blue 134, and green 46. This is the problem I'm hoping to solve. How can I get the red to be 239, blue 152, and green 58 so that the output result color matches what the user inputs as normal RGB?
Those colors of in my verbose listings, I believe, are the RGB colors. If you want the same colors as input, then you must use sRGB for your output color space.

If I misunderstand, then please clarify further.
mackermedia
Posts: 15
Joined: 2013-01-25T12:59:01-07:00
Authentication code: 6789

Re: sRGB to RGB colorspace / profile not working?

Post by mackermedia »

Those colors of in my verbose listings, I believe, are the RGB colors. If you want the same colors as input, then you must use sRGB for your output color space.
I'm struggling with how to reframe my question more clearly...

My question put as simply as possible is this:
I want to input values as RGB (NOT sRGB). I then want the values output to be RGB (NOT sRGB). Is this possible?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: sRGB to RGB colorspace / profile not working?

Post by fmw42 »

mackermedia wrote:
Those colors of in my verbose listings, I believe, are the RGB colors. If you want the same colors as input, then you must use sRGB for your output color space.
I'm struggling with how to reframe my question more clearly...

My question put as simply as possible is this:
I want to input values as RGB (NOT sRGB). I then want the values output to be RGB (NOT sRGB). Is this possible?
Possibly, you need to use profiles to convert from sRGB to RGB and to input values in linear RGB colors, you would have to use

icc-color(rgb, r, g, b) where r,g,b range from 0 to 1 (divide R,G,B in range 0 to 255 by 255 to get values for r,g,b in range 0 to 1 and keep the fractions.) see http://www.imagemagick.org/script/color.php

But the image will still be labeled colorspace sRGB, however, the profiles will do the proper thing.



239/255=0.937254901960784
152/255=0.596078431372549
59/255=0.231372549019608
convert -size 100x100 xc:"icc-color(rgb,0.937,0.596,0.231)" -profile /Users/fred/images/Profiles/sRGB.icc -profile /Users/fred/images/Profiles/GenericRGBProfile.icc -depth 8 test2.tif

identify test2.tif

Code: Select all

Image: test2.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 100x100+0+0
  Units: PixelsPerInch
  Type: Palette
  Base type: TrueColor
  Endianess: LSB
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 233 (0.913725)
      max: 233 (0.913725)
      mean: 233 (0.913725)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Green:
      min: 134 (0.52549)
      max: 134 (0.52549)
      mean: 134 (0.52549)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Blue:
      min: 46 (0.180392)
      max: 46 (0.180392)
      mean: 46 (0.180392)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Image statistics:
    Overall:
      min: 46 (0.180392)
      max: 233 (0.913725)
      mean: 137.667 (0.539869)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
  Colors: 1
  Histogram:
     10000: (233,134, 46) #E9862E srgb(233,134,46)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 100x100+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: TopLeft
  Properties:
    date:create: 2014-02-04T15:53:39-08:00
    date:modify: 2014-02-04T15:53:39-08:00
    icc:copyright: Copyright 2007 Apple Inc., all rights reserved.
    icc:description: Generic RGB Profile
    icc:manufacturer: Generic RGB Profile
    icc:model: Generic RGB Profile
    signature: eae035403546fb560619e5a865731ff9110a3e6c9749c3a074a126029bb38f87
    tiff:document: test2.tif
    tiff:endian: lsb
    tiff:photometric: RGB
    tiff:rows-per-strip: 27
  Profiles:
    Profile-icc: 1328 bytes
  Artifacts:
    filename: test2.tif
    verbose: true
  Tainted: False
  Filesize: 31.7KB
  Number pixels: 10K
  Pixels per second: 1MB
  User time: 0.000u
  Elapsed time: 0:01.009
  Version: ImageMagick 6.8.8-4 Q16 x86_64 2014-01-29 http://www.imagemagick.org
That is the best I can suggest.

My guess is that IM is showing the sRGB color values equivalent to the linear RGB values specified. So I am not sure if this answers your question or not. The issue is that the profiles are needed to do the proper conversion and you need some tool that interprets linear color values and not sRGB values.

If that does not answer your question, then one of the IM developer or someone who understand color management better than me needs to explain.


PS if you create these three images and display them, you will see the colors are different for the first vs the second and that the second and third are the same. IM converts the icc_colors from linear to sRGB before applying, then the profiles convert to RGB


convert -size 100x100 xc:"rgb(239,152,59)" -depth 8 orange_srgb.tif

convert -size 100x100 xc:"icc-color(rgb,0.937,0.596,0.231)" -profile /Users/fred/images/Profiles/sRGB.icc -profile /Users/fred/images/Profiles/GenericRGBProfile.icc -depth 8 orange_rgb.tif

convert -size 100x100 xc:"rgb(239,152,59)" -profile /Users/fred/images/Profiles/sRGB.icc -profile /Users/fred/images/Profiles/GenericRGBProfile.icc -depth 8 orange_rgb2.tif

convert orange_srgb.tif show:
convert orange_rgb.tif show:
convert orange_rgb2.tif show:
Post Reply