Page 1 of 3

[SOLVED] convert from sRGB to linear RGB

Posted: 2012-06-25T07:22:37-07:00
by NicolasRobidoux
I thought I had this under control, but apparently not.
Bleeding edge svn IM7 r8469 (this morning's) compiled in HDRI mode. (There were checked in changes to colorspace.c yesterday. Have not looked at what they had to do with.)
I want to convert a stripped 16-bit sRGB striped tiff (curios.tif, from the 16bit840x840images test image bank http://www.imagemagick.org/download/ima ... es/images/) to a linear RGB image with sRGB primaries, and then I want to convert it back.

I thought the following would do the job, but it does not:
Conversion to linear RGB from sRGB:

Code: Select all

magick curios.tif -set colorspace sRGB -colorspace RGB RGB.tif
The resulting image has contents identical to curios.tif. Same result with

Code: Select all

magick curios.tif -colorspace RGB RGB.tif
On the other hand, this appears to work (in the reverse direction):
Conversion to sRGB from linear RGB:

Code: Select all

magick RGB.tif -set colorspace RGB -colorspace sRGB sRGB.tif
What am I missing?

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T07:25:48-07:00
by NicolasRobidoux
I'm going to see if I can figure out what to do from viewtopic.php?f=3&t=21161&p=86272&hilit=XYZ#p86254.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T07:51:03-07:00
by NicolasRobidoux

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T08:40:58-07:00
by NicolasRobidoux
Either I am really confused, or something is broken.

Code: Select all

magick rose: rose.tif
magick rose.tif -set colorspace sRGB -colorspace RGB roseRGB.tif
These two images are identical, and they should not.

This is not a TIFF issue: They are the same if I use .ppm.

-----

Now, I'll recompile without HDRI to see if this is the problem.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T09:39:34-07:00
by NicolasRobidoux
This is not an HDRI issue: Same with plain compile.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T09:44:36-07:00
by NicolasRobidoux
I think that this either is an undocumented change, or a bug:
The behavior of the following commands appears to have changed since viewtopic.php?f=3&t=20751&p=83893&hilit ... RGB#p84098.
Whence

Code: Select all

magick rose: rose.ppm
magick rose.ppm -colorspace RGB -filter Box -resize 35x23 -colorspace sRGB rose1.ppm
magick rose.ppm -set colorspace sRGB -colorspace RGB roseRGB.ppm
magick roseRGB.ppm -filter Box -resize 35x23 roseSMALL.ppm
magick roseSMALL.ppm -set colorspace RGB -colorspace sRGB rose2.ppm
used to produce two identical images (if I'm not mistaken), it does not anymore. The reason for it would appear to me to be that, now, roseRGB.ppm is identical to rose.ppm.

P.S. See below: It's not a bug, it's a feature.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T10:05:17-07:00
by NicolasRobidoux
I'm doing

Code: Select all

svn update -r 8219
to see how this version behaves.

P.S. It produces two different images too.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T10:53:07-07:00
by NicolasRobidoux
I may be mistaken that the above code used to give the same image. The maximum difference is zero, but the minimum difference is negative. So, I may have missed that one image was always "below" the other.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T10:57:16-07:00
by magick
Ideally all formats would declare their colorspace and gamma, many do not. Without this information we must make assumptions about these attributes. For PNM, we assume sRGB. When you write PNM, ImageMagick converts the colorspace to sRGB. We could easily support writing linear RGB to PNM but then the user has no way of knowing its linear RGB and would assume sRGB. The user must then explicitly set the colorspace to linear RGB. If we always assume sRGB, we get consistent results without user intervention. What's your preference?

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T10:57:47-07:00
by NicolasRobidoux
This would appear to possibly be related to this: viewtopic.php?f=3&t=20826.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T11:02:19-07:00
by NicolasRobidoux
Cristy: This automatic conversion of PNM to sRGB is not what I expected, given that I consider it to be a "neutral storage" format.
On the other hand, maybe this convention is what "the majority" now expects. I have no idea.
In any case I just used PPM to to see if this was a TIFF side effect.
STRIKE THAT: It's TIFF I really care about.
Does it autoconvert to sRGB too?

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T11:08:22-07:00
by NicolasRobidoux
Given that I also don't get identical rose1.tif and rose2.tif in the following, and that the rose.tif and roseRGB.tif images are identical, it would appear to me that TIFF is also automatically converted to sRGB. (Argh!)

Code: Select all

magick rose: rose.tif
magick rose.tif -colorspace RGB -filter Box -resize 35x23 -colorspace sRGB rose1.tif
magick rose.tif -set colorspace sRGB -colorspace RGB roseRGB.tif
magick roseRGB.tif -filter Box -resize 35x23 roseSMALL.tif
magick roseSMALL.tif -set colorspace RGB -colorspace sRGB rose2.tif

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T11:12:29-07:00
by fmw42
Withdrawn, I see you are using "magick" so IM 7.

In IM 6.7.7.9, I get


convert rose: -colorspace RGB rose.tiff

idvs rose.tiff (my short verbose info script)

Image: rose.tiff
Geometry: 70x46+0+0
Page geometry: 70x46+0+0
Class: DirectClass
Colorspace: sRGB
Type: TrueColor
Depth: 8-bit
Alpha: False
Channels: srgb
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)
Overall:
min: 22 (0.0862745)
max: 255 (1)
mean: 105.147 (0.412341)
standard deviation: 59.4199 (0.233019)


I would have thought that it would be colorspace RGB and gamma 1? But perhaps that is only true for IM formats such as miff and mpc? I am no expert on Tiff but perhaps it does not support a linear RGB colorspace.

I guess Magick will have to clarify further.

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T11:31:51-07:00
by NicolasRobidoux
Actually, what I want most to do right now is to be able to convert images like curios.tif (16-bit stripped sRGB TIFF) to 16-bit linear RGB PPM.
Can I do this with IM7?

Re: convert from sRGB to linear RGB

Posted: 2012-06-25T11:35:42-07:00
by NicolasRobidoux
I am not sure what I like is what should be done for "the world", but I find it extremely counterintuitive that explicit specification of a colourspace leads to an automatic conversion for a format which is not explicitly linked to a colourspace.
For PNG, I understand: PNG is sRGB. (Although nothing really should prevent someone to store any kind of 3-band things in PNG.)
For TIFF or PNM, not really.

It just would appear to me that if users are given the power of using -colorspace to navigate between colourspaces (and deal with pseudo-images with nonstandard number of bands etc), maybe they should be given the responsibility of converting to the right colorspace if they are not in it to start with. Even, possibly, with PNG.

I certainly would not complain if I had to use -colorspace sRGB before saving to PNG when my image is not already in sRGB.

But maybe other people would complain?

-----

Need to take more painkillers and will hopefully think more clearly when they start taking effect. (Ear infection *&^%$#@#!)