Page 1 of 3

Montage - Colorspace Questions

Posted: 2014-06-22T14:56:20-07:00
by olafkarsten
Hello, I have 5 images - tiff, 250dpi, CIELab and want to montage them in one row with a few pixels space inbetween.

That is the code I guessed together, but something goes wrong with the colorspace. The single Images in the montage looks wrong. Not sure what happens.

Code: Select all

montage -tile 5x -geometry +225+225 *20cm*.tif miff:- | convert - -depth 8 -colorspace Lab montage.tif
Thanks for any hint.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T16:10:47-07:00
by snibgo
It is difficult to guess without seeing the inputs and output, but you are converting to Lab, with "-colorspace Lab". I don't know why. If all goes well, this shouldn't be needed.

You might need to convert inputs to sRGB first, and convert back to Lab at the end.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T16:41:48-07:00
by fmw42
snibgo wrote:You might need to convert inputs to sRGB first, and convert back to Lab at the end.
I believe snibgo is correct and this is likely the issue. I suspect montage only wants to work with sRGB images. It is more primitive that convert.


try

Code: Select all

convert *20cm*.tif -colorspace sRGB miff:- | montage -tile 5x -geometry +225+225 - miff:- | convert - -depth 8 -colorspace Lab montage.tif
If that fails, post a few of your images to some free hosting service such as dropbox (public folder) and put links here so we can examine your images and test with them. Just a couple would be sufficient for testing montage.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T16:44:52-07:00
by olafkarsten
I have some tif files in an directory. All files are in colorspace Lab and the output tif has to be in this colorspace too. Seems that montage ignores the colorspace setting. I would like to use montage, as it can handle a variable number of input images an put it in an 5x style output image.

So far I ended with

Code: Select all

convert *20cm*.tif -set colorspace LAB -colorspace sRGB -gravity center -background white -extent 2200x2100 -colorspace lab +append -depth 8 montage.tif
Somewhat like this a few days ago. viewtopic.php?f=1&t=25749

I will have to write a script to handle a variable number of input images and add a new row after every five images. I don't like a convert from Lab to sRGB.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T16:47:00-07:00
by olafkarsten
fmw42 wrote:I believe snibgo is correct and this is likely the issue. I suspect montage only wants to work with sRGB images. It is more primitive that convert.
Yepp, thats what I figured out, too. I will go with convert.

Thanks

Re: Montage - Colorspace Questions

Posted: 2014-06-22T20:01:02-07:00
by snibgo
It seems a shame to convert colorspace twice. I would leave it in Lab, and use the hex notation for the background. White in Lab would be #ffff80008000, I suppose.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T20:52:40-07:00
by olafkarsten
snibgo wrote:It seems a shame to convert colorspace twice. I would leave it in Lab, and use the hex notation for the background. White in Lab would be #ffff80008000, I suppose.
Look at that
viewtopic.php?f=1&t=25749

Seems, that for the background handling its convertet to sRGB anyway. But as far as I understand the command it is not convertet forth and back for the entire image. The -set colorspace options sets the colorspace for the image und the -colorspace option for the next command sequence - in this case the background setting for the extent part. But may be, I'm totally wrong. The idea comes from Fred. I guess he knows better ... :)

Re: Montage - Colorspace Questions

Posted: 2014-06-22T22:25:05-07:00
by snibgo
I think that "white" is shorthand for "#fff". If operating on an image in sRGB or RGB space, this really is white. But if the image is Lab (or CMY or ...) the value #fff isn't white.

The operations "-set colorspace X" and "-colorspace X" affect an image. I think they have no effect on the meaning of "white" or any other colour name.

For example:

Code: Select all

convert -size 100x100 gradient:red-blue -colorspace Lab -background white -extent 200x200 -colorspace sRGB w1.tiff

convert -size 100x100 gradient:red-blue -colorspace Lab -background #fff -extent 200x200 -colorspace sRGB w2.tiff

convert -size 100x100 gradient:red-blue -colorspace Lab -background #ffff80008000 -extent 200x200 -colorspace sRGB w3.tiff
w1.tiff and w2.tiff have a red extent. w3.tiff has an almost white extent.

Re: Montage - Colorspace Questions

Posted: 2014-06-22T23:43:07-07:00
by fmw42
This gives me the LAB equivalent of white


convert -size 1x1 xc:white -colorspace LAB -set colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (99.9985%,50.0038%,49.9931%) #FFFE80027FFB srgb(99.9985%,50.0038%,49.9931%)

So using that color, gives me a white background in snibgo's example

Code: Select all

convert -size 100x100 gradient:red-blue -colorspace Lab -background "srgb(99.9985%,50.0038%,49.9931%)" -extent 200x200 -colorspace sRGB 1tmp.tiff
I suspect that it is really srgb(100%,50%,50%) to be more precise.

Re: Montage - Colorspace Questions

Posted: 2014-06-24T00:33:24-07:00
by olafkarsten
I'm somewhat confused. If my input image(s) and my outputimage both have colorspace lab, why the heck I have to give the backgroundcolor in something like hex or srgb instead of cielab. But beside this, the code form snibgo works (fred's too). Thanks for the help.

And a last question to be sure: If I set the backgroundcolor in hexcode - the colorspace is not converted - so all the operation are in colorspace lab? Thats what we want, so I'm happy and will take that code. Thanks to all.

Re: Montage - Colorspace Questions

Posted: 2014-06-24T00:52:25-07:00
by olafkarsten
fmw42 wrote:This gives me the LAB equivalent of white

convert -size 1x1 xc:white -colorspace LAB -set colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (99.9985%,50.0038%,49.9931%) #FFFE80027FFB srgb(99.9985%,50.0038%,49.9931%)
Aah using this, gives the cielab notion too.

Code: Select all

convert -size 1x1 xc:white -set colorspace LAB txt:
# ImageMagick pixel enumeration: 1,1,65535,cielab
0,0: (100%,49.9992%,49.9992%) #FFFF7FFF7FFF cielab(100%,49.9992%,49.9992%)

That leads me to - what I think is - the source of my problem. The notation of the cielab. http://www.imagemagick.org/script/color.php states cielab notation is "cielab(100,50,50)" but that doesn't work for background color. Using -background 'cielab(100%,50%,50%)' works.

Re: Montage - Colorspace Questions

Posted: 2014-06-24T03:29:27-07:00
by snibgo
olafkarsten wrote:If my input image(s) and my outputimage both have colorspace lab, why the heck I have to give the backgroundcolor in something like hex or srgb instead of cielab.
Individual images have colorspaces, but there is no overall concept in IM that "I am now working in LAB."

Most operations are purely arithmetical -- pixel values are changed, and the colorspace (which defines what those values mean) isn't relevant.

This means that colour names have to be used carefully. If I set a background to "khaki", the result will look different, depending on whether my image is RGB, sRGB or anything else. The value will always be #F0E68C, but what this looks like will depend on the colorspace.

Values in expressions like "cielab(a,b,c)" can usually be expressed either as absolute values (typically 0 to 255) or as percentages of quantum with a "%" sign. Percent is usually the better option.

Re: Montage - Colorspace Questions

Posted: 2014-06-24T10:05:53-07:00
by fmw42
IM does not keep track of the colorspace when writing an image. So you have to tell it as appropriate how to change colorspace and from what colorspace it is coming. The use of -set colorspace xxx tells IM what you have and -colorspace xxx tell IM what you want to convert to.

Re: Montage - Colorspace Questions

Posted: 2014-06-24T22:24:58-07:00
by olafkarsten
Tanks both. I think I got it (At least I hope so).

Re: Montage - Colorspace Questions

Posted: 2014-06-30T11:13:19-07:00
by olafkarsten
Sorry, but I have to come back.

Background: We creates the .tif files for use in textile printers. These printers use LAB colorspace and they know exactly what white is.

Problem: all the above solutions gives us a background that is visually (on screen) white, but not for a LAB aware printer.

I'm not sure, where I should look. I have testet all kind of notation for the background color, and I'm not sure, if we haven't a bug somewhere sitting around. Look at this

Code: Select all

convert -size 1x1 xc:white -set colorspace srgb -depth 8 srgb-white-pixel.png
convert srgb-white-pixel.png -format %c histogram:info:-
gives: 1: (255,255,255) #FFFFFF white

totally fine. Now:

Code: Select all

convert srgb-white-pixel.png -colorspace Lab -depth 8 -format %c histogram:info:-
gives: 1: (255,128,127) #FF807F cielab(255,128,127)

In my mind, pure white conversation should be
1: (255,127,127) #FFFFFF cielab(255,127,127)

And thats exactly what happens with our printfiles the white gets converted to some light color, but not pure white.

Comments?