-set colorspace, -colorspace?

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?".
Post Reply
salvati.marc

-set colorspace, -colorspace?

Post by salvati.marc »

Hi guys,
In my search of understanding color space, i try to understand what image magick does with -colorspace, -set colorspace.
I found some strange behaviors... that i dont really understand.
using a dpx file created with the command

Code: Select all

convert -size 100x100 plasma: -colorspace Log testplasma.dpx
I found no difference between the following commands, the result is always the same testplasma.jpg

Code: Select all

convert -colorspace Log testplasma.dpx -colorspace Log testplasma.jpg
convert -colorspace RGB testplasma.dpx -colorspace RGB testplasma.jpg
convert -colorspace Log testplasma.dpx -colorspace sRGB testplasma.jpg
convert -colorspace RGB testplasma.dpx -colorspace sRGB testplasma.jpg
...
...

If I replace with "-set colorspace" then pics are really different...

Code: Select all

convert -set colorspace Log testplasma.dpx -set colorspace Log testplasma.jpg
convert -set colorspace RGB testplasma.dpx -set colorspace RGB testplasma.jpg
convert -set colorspace Log testplasma.dpx -set colorspace sRGB testplasma.jpg
convert -set colorspace RGB testplasma.dpx -set colorspace sRGB testplasma.jpg
...
...

But I dont really understand how it works. If someone could explain me...
Is there any meaning to put more than one colorspace?

Code: Select all

convert -set colorspace RGB -colorspace Log testplasma.dpx -set colorspace Log -set colorspace sRGB testplasma.jpg
thanks in adavance for any help.
Regards
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -set colorspace, -colorspace?

Post by anthony »

-colorspace changes the way the image is stored in memory
-set colorspace just sets the colorsapce of the image without conversion

Many image formats (like JPG) do not use difference colorspaces without using some time of color profile, as such the image is converted back to RGB colorspace unless a color profile has been defined.

That is why you don't see a difference. It is only different IN MEMORY!


See IM Examples, Basics, ColorSpace
http://www.imagemagick.org/Usage/basics/#colorspace
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

the command -set colorspace or -colorspace itself does not make a conversion.
But i m converting from dpx to jpg, so there is a conversion, and i think it uses the -colorspace -set -colorspace information to achive conversion
The proof if that even if Jpg does not support colorspace, the folowwing commands gives different results:

Code: Select all

convert -colorspace Log testplasma.dpx -set colorspace Log testplasma.jpg
convert -colorspace Log testplasma.dpx -set colorspace RGB testplasma.jpg
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

Another troubling things is that:

Code: Select all

convert -colorspace RGB testplasma.dpx -set colorspace sRGB testplasma.jpg
convert -colorspace Log testplasma.dpx -set colorspace sRGB testplasma.jpg
gives different results.
I guess that the representation in memory should have no influence on the conversion process... but it has...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -set colorspace, -colorspace?

Post by anthony »

salvati.marc wrote:

Code: Select all

convert -colorspace Log testplasma.dpx -set colorspace Log testplasma.jpg
convert -colorspace Log testplasma.dpx -set colorspace RGB testplasma.jpg
It makes a difference particularly if you IM is a Q8 version. -colorspace does modify the image!
by JPG modifys it back.

NOTE that the IM backward compatiblity option handler will read the image first then run -colorspace on the image. The -set in the first command is redundant.

However in thesecond command you have the image in memory in LOG colorspace, but then tell IM it is RGB color space without conversion (using -set), as such when it goes to save as JPG, suddenly it find it does not need to convert, so you are now outputing a LOG colorspace as a RGB image!

It may also be a 'fake' colorspace (like the GrayScale colorspape). I am just not certian about it.



The next message using sRGB has recently had a bug report about. I believe unless you are using the latest version of IM it is broken and not symmetrical in its conversions.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

If i understance well what you say,
The following commmand should give me a Jpg with the same pics as in my dpx.

Code: Select all

convert -colorspace sRGB testplasma.dpx -set colorspace RGB testplasma.jpg
-colorspace reads the dpx and store pic in sRGB format. Stores it as sRGB format without any conversion in my jpg file.
But it does not work like this.

It seems that this command gives me the right result(sRGB data in my Jpg file).

Code: Select all

convert -colorspace RGB testplasma.dpx -set colorspace sRGB testplasma.jpg
I guess that -colorspace RGB tells IM to read the pic and make the log to linear conversion. Then the -set colorspace convert it to sRGB and stores it in the jpg file. I have sRGB data in my jpg file, whent i open it in Nuke with sRGB color space, I have the same picture as in my dpx original file.

Regarding what you said, I think that I should be able to change the -set colorspace XXX to any valuem since it does not perform any conversion.... which is not the case. if I change it, the result change.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -set colorspace, -colorspace?

Post by anthony »

salvati.marc wrote: The following commmand should give me a Jpg with the same pics as in my dpx.

Code: Select all

convert -colorspace sRGB testplasma.dpx -set colorspace RGB testplasma.jpg
-colorspace is NOT an input image setting. technically you should do..

Code: Select all

convert testplasma.dpx -colorspace sRGB -set colorspace RGB testplasma.jpg
That is: read image, convert to sRGB colorspace, tell IM it is not actually RGB, and save.

However there was some discussion in another recent 'bug' about what -colorspace sRGB is really doing. You may like to check it and upgrade your IM version.

-colorspace reads the dpx
color space does not do anyting of the sort. It is an operator.= of existing images in memory.
However Im has a old 'legacy' support, so that instead of a 'no image' error it will wait until
it has actually read in some images, before processing the -colorspace option.
See http://www.imagemagick.org/Usage/basics/#legacy
I guess that -colorspace RGB tells IM to read the pic and make the log to linear conversion. Then the -set colorspace convert it to sRGB and stores it in the jpg file.
More likely the IM dpx image decoder is reconising any 'log' format and converting.
This is controled by the -type setting.
http://www.imagemagick.org/Usage/basics/#type
I have sRGB data in my jpg file, whent i open it in Nuke with sRGB color space, I have the same picture as in my dpx original file.
But remember to tell IM and other programs when reading this JPG that it is really sRGB jpeg.
Maybe the JPG image should have a color profile included in it!

Regarding what you said, I think that I should be able to change the -set colorspace XXX to any valuem since it does not perform any conversion.... which is not the case. if I change it, the result change.
The JPG coder sees the current 'image' colorspace, knows their is no color profile, so converts the image to RGB. It just does not do that conversion if the image is already RGB.

What you really want is to somehow set a JPG color profile for sRGB, so the JPG coder can convert the image to match that profile instead of RGB.


In summery; You are fighting the built-in automatic support in IM in very bad ways.

JPG uses color profiles, DPX does not. As such you should be adding the appropriate color profile.
http://www.imagemagick.org/Usage/formats/#color_profile

You can download color profiles from International Color Consortium.
http://www.color.org/srgbprofiles.xalter
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

Code: Select all

convert testplasma.dpx -colorspace sRGB -set colorspace RGB testplasma.jpg
That is: read image, convert to sRGB colorspace, tell IM it is not actually RGB, and save.
However there was some discussion in another recent 'bug' about what -colorspace sRGB is really doing. You may like to check it and upgrade your IM version.
Finally, maybe because of that bug, I cant get it to work properly.
I guess that theoritically, without
fighting the built-in automatic support in IM in very bad ways.
, I would need to do something like :

Code: Select all

convert testplasma.dpx -colorspace sRGB -profile sRGB.icm testplasma.jpg
But it does not work...
Having or not having the -profile sRGB.icm does not change anything(in the pixel data).
The only difference is in the metadata.
Having or not having the -colorspace sRGB does not change anything.
I have my colors like in my dpx file, in RGB linear space.

So I do something like

Code: Select all

convert testplasma.dpx -colorspace RGB -set colorspace sRGB -profile sRGB.icm testplasma.jpg
And it works, as long as i
remember to tell IM and other programs when reading this JPG that it is really sRGB jpeg.
But again, the -profile sRGB.icm does not change anything to the data. It s only in the metadata, and does not change anything the way the file is read by Nuke.

As for the -type parameter... there is no way to specify sRGB or Log or any colorspace. We can only specify
Bilevel, Grayscale, GrayscaleMatte, Palette, PaletteMatte, TrueColor, TrueColorMatte, ColorSeparation, ColorSeparationMatte, or Optimize.
My conclusion is that
-profile: set metadata concerning color profile if supported by target file type
-colorspace : change the way actual pixel are represented
-set colorspace: sets the file type metadata AND makes a conversion from the previous colorspace to the given colorspace before storing data in output image.

As for my dpx -> jpeg conversion

Code: Select all

convert testplasma.dpx -colorspace RGB -set colorspace sRGB -profile sRGB.icm testplasma.jpg
-profile sRGB.icm: include metadata for sRGB color profile
-colorspace: i need to use it to get the data to a easy to convert format: RGB
-set colorspace: really tricky.... the "set metadata" colorspace seems to be supported inside IM. then it considers the output file to store those data, regardless of if the format support it or not. Jpeg does not support explicitaly colorspace (since it support profiles). But sill i need to store sRGB data if I want to match the included profile information.
If i just use -colorspace sRGB, not colorspace is set, and by default, Jpeg is RGB. So it does not save sRGB data information with the following command.

Code: Select all

convert testplasma.dpx -colorspace RGB -colorspace sRGB -profile sRGB.icm testplasma.jpg
Or everything I m doing is only different from what i shoud do, but what I should do does not work because of the bug in sRGB handling....
I just checked the change log and the sRGB bug is not yet included in the distribution... So i ll wait i guess.

If there was no bug, I think I should be able to use just one of those command (which one?):

Code: Select all

convert testplasma.dpx -colorspace sRGB testplasma.jpg

Code: Select all

convert testplasma.dpx -profile sRGB.icm testplasma.jpg

Code: Select all

convert testplasma.dpx -colorspace sRGB -profile sRGB.icm testplasma.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -set colorspace, -colorspace?

Post by anthony »

salvati.marc wrote: And it works, as long as i
remember to tell IM and other programs when reading this JPG that it is really sRGB jpeg.
But again, the -profile sRGB.icm does not change anything to the data. It s only in the metadata, and does not change anything the way the file is read by Nuke.
Sounds like Nuke does not handle profiles very well. Not all programs understand JPG profiles, IM itself only does so in a limited way (see below). Most high end Web browsers and Photo Processors generally do understand JPEG profiles.
My conclusion is that
-profile: set metadata concerning color profile if supported by target file type
-colorspace : change the way actual pixel are represented
-set colorspace: sets the file type metadata AND makes a conversion from the previous colorspace to the given colorspace before storing data in output image.
Almost right...
-profile set metadata concerning color profile, modify the color data to match profile change on second (or more) -profile option
-colorspace : change the way actual pixel are represented
-set colorspace : tell image the data is represented this way, but does not touch the data

Remember the JPEG coder (and many others) actually does an internal -colorspace operation if the current data colorspace (whatever it is declared as) is not usable by the file format (at least not normally). Using -set colorspace RGB will ensure JPEG coder does not modify the data, but just output it as if normal RGB.

Profile conversion will need two profiles when none are present. One to specify the current data profile (if not present, which I do not think it is), and the second to modify it, and specify the profile to store with the image.

Yes it is a bit weird but that was the way IM developed historically.

It is a bit like first using -set colorname to specify the current data represention, the using -colospace to actually modify the data to that representation, but using much more complex and free form color data specifications (profiles) rather than simple labels for the representation.

I do not know exactly what -colorspace sRGB does. It is a new addition and not one I have studied or used. It may be wrong, it may be right, I don't know. All I know is that their is some development chatter about it, making me doubt how well implemented it is. Profiles (two of them) may be the better more correct way to handle it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

Remember the JPEG coder (and many others) actually does an internal -colorspace operation if the current data colorspace (whatever it is declared as) is not usable by the file format (at least not normally). Using -set colorspace RGB will ensure JPEG coder does not modify the data, but just output it as if normal RGB.
I got that...
So basically I understand that i should be able to do the following command to get a sRGB jpeg

So here is the command I shoud use BUT that does not work
According to viewtopic.php?f=3&t=17150, it seems it achieve the opposite of what I want.

Code: Select all

convert testplasma.dpx -colorspace sRGB -set colorspace RGB testplasma.jpg
the -colorspace does the conversion, and the -set colorspace RGB fools the conversion to JPG, because if there is no profile, default storage is in RGB.

The trick is that actual sRGB conversion does the inverse job we would like it to do so the following commands does the job i want:

Code: Select all

convert testplasma.dpx -colorspace RGB -set colorspace sRGB testplasma.jpg
-colorspace RGB convert to linear space, -set colorspace sRGB change metadata, during jpg conversion, sRGB-> RGB conversion has to happen (default Jpg is stored in RGB), but as it does the inverse it should do, it becomes: RGB->sRGB.

I think, I got why it works this way and I have to wait until a patch is issued.


BUT All those trick should be avoided by the uses of profiles you said me
Profile conversion will need two profiles when none are present. One to specify the current data profile (if not present, which I do not think it is), and the second to modify it, and specify the profile to store with the image.
no matter how many -profile sRGB.icc I put in my command, the result is not changed...
It seems to me that the -profile command just does not work, it just set the metadata. But actually, -profile sRGB.icc -profile sRGB.icc means: input is sRGB, output is sRGB. so maybe it just mean: no conversion, since it is the same profile
So what is the color profile of my dpx file? i have no idea...
I can do something like
convert testplasma.dpx -colorspace sRGB -profile sRGB.icc -profile sRGB.icc testplasma.jpg
So the problem comes back to the -colorspace sRGB parameters.
Sounds like Nuke does not handle profiles very well. Not all programs understand JPG profiles, IM itself only does so in a limited way (see below). Most high end Web browsers and Photo Processors generally do understand JPEG profiles.
Nuke just ignores it. You specify the colorspace every time you read a picture, so you dont really need the color profile.

My conclusion is:
1- conversion from RGB/Log to sRGB does not work the way it should. A patch will soon be available I guess.
2- -profile XXX : i dont know how i could use it to convert from Log dpx data to sRGB data. if the output is sRGB profile, what is the input color profile?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -set colorspace, -colorspace?

Post by anthony »

Using the same profile will make no color change. it is that profile.

Try this

-profile RGB.icc -profile sRGB.icc

that says the dpx input is RGB and should be converted to sRGB for jpeg.

At least that is what I believe it should do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
salvati.marc

Re: -set colorspace, -colorspace?

Post by salvati.marc »

I dont know where to find the RGB.icc file....
I tried to use some AdobeRGB.icc files, and i get an error like:
Magick:Color profile operates on another colorspace
there is a lot of color profile available, but not of them is a pure RGB linear one.
and i dont know which one is supposed to match the dpx file...
Post Reply