Page 1 of 1

need help with Lighten composite using (+clone)

Posted: 2011-11-02T17:00:17-07:00
by luckyluca
Hello,

I would like to soft lighten an image with a blurred version of itself, except that I would like to color correct the blurred version a little bit before compositing it back.
The following line works fine:
convert INPUT ( +clone -blur 0x18 -gamma 1.8 ) -compose Lighten -composite OUTPUT

however additional color corrections of the blurred clone using a multiply operation within brackets doesn't seem work:
convert INPUT ( +clone -blur 0x18 -gamma 1.8 -compose Multiply -size 1024x1024^ canvas:red) -compose Lighten -composite OUTPUT

what am I doing wrong?

Thanks for your help!
Luca

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-02T17:45:57-07:00
by fmw42
convert INPUT ( +clone -blur 0x18 -gamma 1.8 -compose Multiply -size 1024x1024^ canvas:red) -compose Lighten -composite OUTPUT
You have several problems here.

1) your must leave space before the closing paren
2) -compose multiply will do nothing as it is a setting and needs its own -composite
3) I don't know what your red image is supposed to do --- you cannot composite 3 images together at the same time (that requires -flatten or one of the other layers methods), nor can you put the -compose before the second image in the parens
4) Often after using one compose method, you need to reset the -compose back to over before using another -compose ... -composite. Not sure in this case, but it does not hurt to add it in, esp if things are not working as expected and see if that helps.
5) In windows, you may need to escape the ^, see http://www.imagemagick.org/Usage/windows/


Perhaps something like this:

convert INPUT ( +clone -blur 0x18 -gamma 1.8 -size 1024x1024^ canvas:red -compose Multiply -composite ) -compose over -compose Lighten -composite OUTPUT

But perhaps it would be best for you to clarify functionally what you are trying to do especially with the red canvas image relative to the INPUT or to the clone

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-03T03:06:21-07:00
by luckyluca
Thanks a lot for your reply, it seems to work fine (Except that I don't quite understand why eheh), I'm now understanding the use of parenthesis and compose flags better.

I'm writing a batch conversion script to create night textures from day textures; basically I'm analizing the image, creating masks, glowing them and multiplying them by arbitrary colors to simulate the night city lighting on aerial day pictures.
In the specific, one of the step required to do something similar to the lighten flower example, except that I wanted to tint the glow reddish:
http://www.imagemagick.org/Usage/compose/#lighten

Here a couple of WIP screens to illustrate what I'm doing:
Image
Image

I removed '-compose over' as it seems not to make any difference and the following seems to work fine:
convert INPUT ( +clone -blur 0x18 -gamma 1.8 -size 1024x1024^ canvas:red -compose Multiply -composite ) -compose Lighten -composite OUTPUT

There are still a few confusing points for me, for instance -level or -gamma in the middle of a convert operation doesn't seem to work; for instance here I wanted to take the resulting B&W mask from the fuzz/fill operation and make it darker by using a gamma or level but this doesn't seem to work and the contribution from the -level operation is nil:
convert INPUT -fuzz 95% -fill black -opaque 'rgb(255,255,255)' -level 0%,100%,0.5 -blur 0x1 -resize 1024x1024 OUTPUT

Thanks
Luca

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-03T10:29:50-07:00
by fmw42
convert INPUT -fuzz 95% -fill black -opaque 'rgb(255,255,255)' -level 0%,100%,0.5 -blur 0x1 -resize 1024x1024 OUTPUT
-level 0%,100% does nothing. the 0.5 for gamma would be the same as using -gamma 0.5.

Can you provide a link to the input you want to start with so we understand what your -fuzz 95% fill black -opaque ... is doing. You can also insert -write tmpX.png anywhere you want to see what the intermediate result is. That way you can figure out what is happening after each option.

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-03T16:03:52-07:00
by luckyluca
thanks for the -write tip, it is now much easier to debug my steps.
Basically I would feed http://img829.imageshack.us/img829/4829/origz.th.jpg as an input and get a rough mask out. I wanted the -level operation to darken the whole brightness down and I ended up using
-fill black -colorize 50% instead.

I'm still confused by why the need to use separate executable files convert and composite when it is still possible to do composite operations with the -compose flag under convert.
I'm also still confused by the cloning and by the layering, but I kind of found a solution: I create a list of batch operations where each output file is the input of the following operation.
This way I can chain a lot of complex operations without making each line too convoluted

Thanks again.

All is left now -and this is really being picky- is a nice way of selecting patches of an image that let's say are white:
only when the white is concentrated in big areas, not the small high frequencies areas.
For instance, in the dark image I posted earlier, only the big slice of white area on the left should be selected. My plan would be to clip such large areas out of the image by painting it black.
I need to investigate what type of filter would give me that :D




fmw42 wrote:
convert INPUT -fuzz 95% -fill black -opaque 'rgb(255,255,255)' -level 0%,100%,0.5 -blur 0x1 -resize 1024x1024 OUTPUT
-level 0%,100% does nothing. the 0.5 for gamma would be the same as using -gamma 0.5.
Can you provide a link to the input you want to start with so we understand what your -fuzz 95% fill black -opaque ... is doing. You can also insert -write tmpX.png anywhere you want to see what the intermediate result is. That way you can figure out what is happening after each option.

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-03T16:15:24-07:00
by anthony
For more debugging hints see IM examples, Basics, Complex Image Processing and Debugging
http://www.imagemagick.org/Usage/basics/#complex

It gives a list of a number of thing you can do to see what is going on.

Re: need help with Lighten composite using (+clone)

Posted: 2011-11-03T17:33:59-07:00
by fmw42
I'm still confused by why the need to use separate executable files convert and composite when it is still possible to do composite operations with the -compose flag under convert.
I'm also still confused by the cloning and by the layering, but I kind of found a solution: I create a list of batch operations where each output file is the input of the following operation.
This way I can chain a lot of complex operations without making each line too convoluted
see
http://www.imagemagick.org/Usage/layers/

esp
http://www.imagemagick.org/Usage/layers/#convert

You can do convert -compose -composite in pairs in a chain in one command. Just finish the first pair, then add the next image and another -compose -composite, etc.