Page 1 of 2

Standardising colorspaces

Posted: 2012-12-11T08:55:10-07:00
by OrangeDog
I have input images from various sources in various colorspaces and need to standardise them, removing all embedded profile stuff, but leaving the resulting images looking the same. Basically I want to achieve what happens when you open them in MSPaint and re-save as a bitmap (then convert back to jpg).

`convert in.png -strip -colorspace RGB out.jpg` results in sRGB input becoming too dark.
`convert in.jpg -strip -colorspace sRGB out.jpg` results in CMYK input becoming too light.

6.7.9-6

Re: Standardising colorspaces

Posted: 2012-12-11T10:47:10-07:00
by snibgo
You might want to standardise on sRGB. Your "-strip" will remove any profiles, so any subsequent conversion won't know the starting point.

Code: Select all

convert infile -colorspace sRGB outfile
should generally work better, but you might also want to remove any profiles after the colorspace conversion.

Re: Standardising colorspaces

Posted: 2012-12-12T02:33:52-07:00
by OrangeDog
That still ends up lightening CMYK input, whether there's a -strip or not.

Re: Standardising colorspaces

Posted: 2012-12-12T07:45:40-07:00
by snibgo
I know little or nothing about CMYK colorspaces, sorry. If you can post the URL of a sample file, someone might take a look.

Re: Standardising colorspaces

Posted: 2012-12-12T08:09:04-07:00
by OrangeDog

Re: Standardising colorspaces

Posted: 2012-12-12T10:02:47-07:00
by snibgo
This seems to do the trick:

Code: Select all

convert Channel_digital_image_CMYK_color.jpg -profile sRGB.icc x.jpg
You probably have a copy of sRGB.icc in the ImageMagick directory. Either copy it to your working directory, or provide the full path in the command.

After the "-profile" command, you can then "-strip" to remove all profiles and comments, or "+profile "*"" to just remove profiles, if you want.

Re: Standardising colorspaces

Posted: 2012-12-12T10:32:51-07:00
by OrangeDog
It certainly looks nicer, but the output still does not exactly match the colours of the input.
I don't want to affect the appearance at all - just standardise the representation for maximum compatibility.

Re: Standardising colorspaces

Posted: 2012-12-12T10:59:07-07:00
by snibgo
OrangeDog wrote:It certainly looks nicer, but the output still does not exactly match the colours of the input.
How do you know?

When I visually compare my result with Windows Photo Viewer or Gimp displaying your original, I can't see any difference. When I save the result from Gimp and use IM to compare the results, there is a small arithmetic difference (RMSE 1.4%), but I can't see it. The difference from Gimp might be that Gimp is using a different sRGB profile.

EDIT: You mention MS Paint. When I open your image in Paint and save it as xPaint.jpg, I can see a difference with my result. There is a slight shift, in the Paint version, away from magenta towards blue. IM compare says the RMSE difference is 3.5%.

Perhaps Paint is using yet another ICC sRGB profile. (There are quite a few. That's the great thing about standards -- so many to choose from.)

Or perhaps Paint is simply wrong. That wouldn't surprise me. I see Channel_digital_image_CMYK_color.jpg was created with Photoshop. If you have PS (I don't), you might use that for comparisons.

Re: Standardising colorspaces

Posted: 2012-12-13T03:34:38-07:00
by OrangeDog
I can see a significant difference on a variety of both Windows and Linux viewers.
Additionally, using -colorspace RGB on that image gives output that does look exactly the same.

Are you using the same version as me? I know colorspace conversions have been pretty broken previously.
Have just checked with 6.8.0-4 as well, and there's the same behavior.

Re: Standardising colorspaces

Posted: 2012-12-13T08:28:29-07:00
by glennrp
snibgo wrote: You probably have a copy of sRGB.icc in the ImageMagick directory.
We had to remove it from the ImageMagick distribution back in June 2012 because of
its unfriendly license. You can get several sRGB profiles from
http://color.org/srgbprofiles.xalter (you will probably have to accept a EULA
before downloading).

Re: Standardising colorspaces

Posted: 2012-12-13T09:18:24-07:00
by snibgo
Can you desribe the difference you see? Is the difference consistent across viewers?


I've tried my Windows 7 command ...

Code: Select all

"%IMG%convert" Channel_digital_image_CMYK_color.jpg -profile "%IMG%sRGB.icc" x.jpg
... for IM versions 6.6.2 Q16, 6.7.6 HDRI, 6.7.9 Q16, 6.8.0-9 Q16, 7.0.0-0 HDRI (2012-10-30). I used the profile sRGB.icc that came with the distribution where there was one; otherwise the icc distributed with 6.7.9.

The results were visually identical to each other (using Microsoft Photo Viewer).

Code: Select all

"%IMG%compare" -metric RMSE x.jpg x680.jpg null:
... showed a maximum difference between them of 0.5%.

In case something remained in the files, I then repeated the tests inserting "-strip" before the output filename. The results were the same.

Re: Standardising colorspaces

Posted: 2012-12-13T10:20:28-07:00
by OrangeDog
Each image on its own appears consistently across all viewers (Microsoft Photo Viewer, Paint, Paint.NET, Explorer and Nautilus thumbnails, eog).

Here's the ouput using the sRGB.icc from 6.7.6:

Code: Select all

$ compare -metric RMSE Channel_digital_image_CMYK_color.jpg out.jpg null:
88.7424 (0.348009)
Using -colorspace sRGB:

Code: Select all

$ compare -metric RMSE Channel_digital_image_CMYK_color.jpg out2.jpg null:
97.0049 (0.380411)
and using -colorspace RGB:

Code: Select all

$ compare -metric RMSE Channel_digital_image_CMYK_color.jpg out3.jpg null:
98.4182 (0.385954)
I'm not sure exactly what that metric is, but out3.jpg is the one that appears identical to the original.
If you can suggest a service to use, I can supply some screenshots of the outputs.

Re: Standardising colorspaces

Posted: 2012-12-13T11:06:30-07:00
by snibgo
You are comparing a CMYK file with a RGB (or sRGB) file. Hardly suprising that there is a massive difference in the pixel values.

[RMSE is "root mean square error". For each pixel, it subtracts the value in one image from that in the other ("error"), and squares this difference ("square error"). It sums this across all pixels, divides by the number of pixels ("mean square error"), and takes the square root ("root mean square error"). As these are 8-bit files, so each value is 0-255, a RMSE of 0.005 or 0.5% represents a change in pixel values of about 1. The pixel values in a CMYK file are totally different to the ones in a RGB file, so the RMSE is huge.]
OrangeDog wrote:Each image on its own appears consistently across all viewers (Microsoft Photo Viewer, Paint, Paint.NET, Explorer and Nautilus thumbnails, eog).
Yes, doubtless, but you have said "output still does not exactly match the colours of the input". In what way doesn't it match? What is the difference? Do you see the same difference in all viewers?

Perhaps you can post a screenshot from a viewer showing Channel_digital_image_CMYK_color.jpg that you consider to be correct, and a screenshot from the same viewer of the output from:

Code: Select all

"%IMG%convert" Channel_digital_image_CMYK_color.jpg -profile "%IMG%sRGB.icc" x.jpg
OrangeDog wrote:... out3.jpg is the one that appears identical to the original.
So, have you solved your own problem?

Re: Standardising colorspaces

Posted: 2012-12-13T12:27:30-07:00
by OrangeDog

Code: Select all

Hardly suprising that there is a massive difference in the pixel values.
Then why did you mention it in the first place?

Code: Select all

Do you see the same difference in all viewers?
If every image appears the same in all viewers, then yes, the differences are also all the same.

Code: Select all

Perhaps you can post a screenshot from a viewer
That's what I just suggested, if you can suggest the best way to post images here.

Code: Select all

So, have you solved your own problem?
No. As per the original post, this command does not preserve the colours in sRGB input.

Re: Standardising colorspaces

Posted: 2012-12-13T12:39:42-07:00
by snibgo
I used IM's "compare" to compare images that were both RGB. One came from my convert, the other from Gimp. They were almost identical. [It's possible that IM and Gimp are equally wrong, of course.] Using "compare" to compare a CMYK file with an RGB file is pointless.
OrangeDog wrote:If every image appears the same in all viewers, then yes, the differences are also all the same.
What are the differences?
OrangeDog wrote:That's what I just suggested, if you can suggest the best way to post images here.
Put them in a public place and paste the URL here.