Resizing cielab image - don't understand background color

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
olafkarsten
Posts: 29
Joined: 2013-06-13T08:35:38-07:00
Authentication code: 6789

Resizing cielab image - don't understand background color

Post by olafkarsten »

Hello, after messing around ...
in short: I need some help.
Goal: Resize input image, after that put it centered on a white canvas. Outputimage have to be in cielab colorspace and tif format, 8bit. Code of choice:

Code: Select all

convert -verbose rose: -colorspace lab -filter quadratic -resize 500x500\! -gravity center -crop 2200x1800+0+0\! -layers flatten -depth 8 -compress LZW rose.tif
Don't work. Background is something in the redish area. Whereas:

Code: Select all

convert -verbose rose: -filter quadratic -resize 500x500\! -gravity center -crop 2200x1800+0+0\! -layers flatten -colorspace lab -depth 8 -compress LZW rose.tif
works (note: colorspace conversion at the end). BUT we have found in our tests, that colorspace conversion to cielab before the resize operation gives us better results.

If you don't have an tif-viewer, use rose.JPG instead. Works, too.

Any help is really appreciated.

Thanx.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing cielab image - don't understand background colo

Post by fmw42 »

IM does not process background colors, except in sRGB, as far as I know. Even if you specify HSL or other acceptable colors, they get converted to sRGB values.

Does this do what you want?

Code: Select all

convert -verbose rose: -colorspace lab -filter quadratic -resize 500x500\! \
-set colorspace LAB -colorspace sRGB \
-gravity center -background white -extent 2200x1800 -colorspace lab\
-depth 8 -compress LZW rose.tif
olafkarsten
Posts: 29
Joined: 2013-06-13T08:35:38-07:00
Authentication code: 6789

Re: Resizing cielab image - don't understand background colo

Post by olafkarsten »

Ah, I see. That information in the morning would have saved me a few grey hairs. :D

Thanks for the fast help. I think that works for a starting point. In our case (a script) it is possible, that the input image is bigger in size than the target canvas - therefore the variant with the crop. But i will play around a bit with your variant and hopefully find a way. In any case - as usual - i have learned something from your post. Thanks very much!!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing cielab image - don't understand background colo

Post by fmw42 »

Not really sure what you are trying to do. So hard to say. It looks like you just want to enlarge rose to 500x500 and then put in inside a (white) background of 2200x1800. -extent will do that for you. See slight reordering of my command above.
olafkarsten
Posts: 29
Joined: 2013-06-13T08:35:38-07:00
Authentication code: 6789

Re: Resizing cielab image - don't understand background colo

Post by olafkarsten »

It perfect fits the bill. I didn't now, that extend actually 'crops'. Works perfect in all test cases. Thanx again.
olafkarsten
Posts: 29
Joined: 2013-06-13T08:35:38-07:00
Authentication code: 6789

Re: Resizing cielab image - don't understand background colo

Post by olafkarsten »

For reference I link to another thread, where we did solve a similiar problem with colorspace and background setting:
- Note: the cielab notation with percent sign (%).
Post Reply