-set 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
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

-set colorspace

Post by GreenKoopa »

Does -set colorspace modify pixel values, or only change the colorspace setting?

convert -size 500x1 gradient:#000-#F00 gradient:#FF0-#000 -set colorspace RGB -resize 450x1 -set colorspace sRGB -append y.png
convert -size 500x1 gradient:#000-#F00 gradient:#FF0-#000 -set colorspace RGB -resize 450x1 -append -set colorspace sRGB z.png
compare -metric ae y.png z.png null:
> 226
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -set colorspace

Post by fmw42 »

It only sets the colorspace (gamma) in the meta data without changing pixel values. To modify the pixels you need to use -colorspace not -set colorspace.

I am not sure why -append is behaving differently. But in one case you are appending linear RGB and then setting it to sRGB. In the other case you are setting the individual images from RGB to sRGB and then appending.

What happens if you simplify it further and just append two different graylevel 1x1 pixels, say one white and one black?

What version of IM are you using and what platform? It may be you are using too old a version of IM?

I can reproduce your results on IM 6.8.8.1 Q16 Mac OSX. If I use one black and one white pixel, it gives zero for the compare -metric AE.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set colorspace

Post by snibgo »

"-set colorspace" doesn't change pixel values. It does change the meaning of those values.

I don't know why there is a difference. If we remove each "-resize", the difference actually increases slightly. However, the RMSE difference is tiny. Really, really small. About 0.3 out of 65535. I would put this down to a rounding difference.

if I run the tests with IM7 (floating point) I get zero difference for both AE and RMSE.
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -set colorspace

Post by GreenKoopa »

snibgo wrote:I would put this down to a rounding difference.
Agreed that it is small, but are pixels being rounded by -append or -set colorspace?

ImageMagick 6.8.8-1 Q16 x64 2013-12-25 on Windows 7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -set colorspace

Post by snibgo »

Code: Select all

%I%convert ^
  -size 500x1 gradient:#000-#F00 gradient:#FF0-#000 ^
  -set colorspace RGB ^
  -append -write z0.png -set colorspace sRGB ^
  z.png
IM v6.8.8-0 reports zero difference between z0.png and z.png. I conclude the difference comes from the "-append".
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: -set colorspace

Post by GreenKoopa »

Agreed, it appears that -append carries out implicit colorspace conversions. I believe that it automatically converts all images to sRGB before appending the images together, then converts the result to the colorspace of the first image. This would explain the above rounding error, and the lost processing time I noticed in an earlier post. I was appending two linear RGB images together into a new linear RGB image, and I didn't realize that -append moved everything through the sRGB colorspace. In conclusion, I didn't expect the rounding error because I didn't know -append had the ability to modify pixel values.
Post Reply