Trouble compositing images onto effects-filled canvases

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
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Trouble compositing images onto effects-filled canvases

Post by Tagomago »

I've taken commands from both Fred's imagemagick scripts and imagemagick tutorials that call for creating a blank canvas, applying changes to it (noise, etc.) and then combining them with the image. In each case, the final image comes out nearly identical to the originial. I must be missing something, possibly because I am converting these to use on Windows (command prompt on Windows 7)

Here is sample code, taken from Fred's mottle script.

Code: Select all

convert -size 670x475 xc: +noise Random -virtual-pixel tile -blur 0x2 -contrast-stretch 0% -channel G -separate temp1.png

composite temp1.png paint.jpg -displace 5x5 mottle.jpg
Here are the input and output images. This is a painting of mine and I'm interested in subtle transformations.

Start
Image
Finish
Image

Note that the image shifted slightly, but that's it.

Here is another example of code, this time using Fred's "disperse" script. The final image also was the same, except it shifted up a few pixels

Sample code:

Code: Select all

convert -quiet -regard-warnings test.jpg +repage tmpA1.mpc

convert -size 296x450 xc: -seed 1 +noise Random -virtual-pixel tile -blur 0x10 -colorspace gray -contrast-stretch 0% tmp0.jpg

convert tmp0.jpg -channel R -evaluate sine 10 -channel G -evaluate cosine 10 -channel RG -separate tmpA1.mpc +swap miff:- | composite - -displace 10x10 final.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble compositing images onto effects-filled canvases

Post by fmw42 »

Does my script, disperse work for you?

What version of IM and and what platform are you using?
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Trouble compositing images onto effects-filled canvases

Post by Tagomago »

fmw42 - I'm using IM 6.6.7.7 on Windows 7 with ample specs.

I tried Cygwin previously to run your disperse script as is, but it had a previously posted error with the IM version that didn't find resolution.

Becuase of that, I've taken to trying to extract the process and plug in values manually. The code I posted is what I took out. With another script, looking at the summary and manually inputting values worked fine.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble compositing images onto effects-filled canvases

Post by fmw42 »

this works fine for me. Note your random image size was not correct per the image you show.


convert -quiet -regard-warnings paint.jpg +repage tmpA1.mpc

convert -size 670x445 xc: -seed 1 +noise Random -virtual-pixel tile \
-blur 0x10 -colorspace gray -contrast-stretch 0% tmp0.jpg

convert tmp0.jpg -channel R -evaluate sine 10 -channel \
G -evaluate cosine 10 -channel RG -separate \
tmpA1.mpc +swap miff:- | composite - -displace 10x10 paint_final.jpg
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Trouble compositing images onto effects-filled canvases

Post by Tagomago »

Thanks for the correction on the image size.

I'm beginning to think I suffer from the "curse of windows," as copying your script exactly did not produce anything different. The image below merely shifting up.

One thought: is the "swap miff" called for in the third line a .miff file that I should have from a previous operation? (I didn't get any warning that it wasn't found)

Also, does the pipeline key | correctly translate for windows?

I'm going to try this series of commands on my other comp to see if I have any luck.

code+image

Code: Select all

convert -quiet -regard-warnings paint.jpg +repage tmpA1.mpc

convert -size 670x445 xc: -seed 1 +noise Random -virtual-pixel tile -blur 0x10 -colorspace gray -contrast-stretch 0% tmp0.jpg

convert tmp0.jpg -channel R -evaluate sine 10 -channel G -evaluate cosine 10 -channel RG -separate tmpA1.mpc +swap miff:- | composite - -displace 10x10 paint_final.jpg
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble compositing images onto effects-filled canvases

Post by fmw42 »

I am not that much of an expert on unix or windows, but the ( miff:- | composite -) combination (i.e. stdout and stdin) may very well be the problem for Windows. Perhaps some Windows expert can clarify. However, you can split that into two commands by saving another tmp file in place of miff:-


convert tmp0.jpg -channel R -evaluate sine 10 -channel G -evaluate cosine 10 -channel RG -separate tmpA1.mpc +swap tmp1.miff
composite tmp1.miff -displace 10x10 paint_final.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Trouble compositing images onto effects-filled canvases

Post by anthony »

Some small things, that will make thing easier....

I don't know why you only see horizontal or vertial displacements. Perhaps your IM is too old, as there are BUGS,
in older versions that limit effects to three image compositions.

Make sure your IM version is greater than version 6.4.4 as that was the version when I 'fixed' displacement mapping.
Better still use version 6.5.4-0, whcih was when I actually LAST did major work on 'mapping' composition methods.

Next your composition is using a greyscale 'source' or 'displacement map' image with a argument of 5x5. As only one greyscale value is provided for BOTH X and Y displacement, the displacement is limited to the diagonal direction, +/-5 pixels in X and +/-5 in Y according to that value (50% grey = 0 displacement).

For non-diagonal (any direction) you need two independent displacement maps, one for X and the other for Y either as a three image composition, or as a single map which uses red for X, and green for Y displacement. The second method is very easy to apply, as you just don't seperate the channels from the random blurred image. All the noise and blur operators are greyscale channel operators, so they effect the red and green channels completely separately.

Also you can use the original image (a clone) to generate a random image (and final map) that is exactly the same size, without needing to know about that size. You don't need to use -size XxY xc: unless starting from scratch

To make to make the displacements clear (without using a 'flicker compare' type program) I used a checkerboard pattern for the original (destination) image. Your supplied test image is too random to see displacement effects very clearly.

I also used convert -composite to do the task, as I find it easier to do things in one command. Fred's script uses composite command, as he wanted his scripts to work on IM's that are older that when the special "compose:arg" definition was added. In IM v6.5.3-4


And finally I used a Virtual pixel setting of Gray (displacement zero) to minimize (by 50%, but not remove) the displacement at the edges (or you can get weird edge effects) during the random image blurring. To get ride of edge displacements, (or make the displacements more circular), a little more will will be needed on the displacement map.
I also used a virtual-pixel black setting for the actual displacement, to show the 'invalid' lookup edge effects that is generated.

Code: Select all

convert -size 200x200 pattern:checkerboard png24:cb.png

convert cb.png \
      \( +clone +noise Random -virtual-pixel Gray -blur 0x8 \) \
      -virtual-pixel Black -define compose:arg=5x5 -compose displace -composite \
      cb_displaced.png
ImageImageImage
You can see from comparing the intersections the displacement was in any direction (in a 5x5 max box)
Remember the other method would be limited to a diagonal displacement (5x5 max)


For more info see IM Examples, Displacment Mapping
http://www.imagemagick.org/Usage/mappin ... ement_maps
This area of IM examples needs a lot more work and examples, (and to move away from all the FX examples used) to demonstrate IM's image mapping capabilities.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Trouble compositing images onto effects-filled canvases

Post by Tagomago »

I really appreciate the detailed replies.

My IM version is 6.6.7-7, and I've only had versions released in the last month installed before on this computer.

I've read over your suggestions and plan on revisiting them shortly to work through them in a thorough manner.

In the meantime, I tried the code you posted. My result is... comically dissimilar.

Image

Here is the code, adapted for windows command prompt, and it should be exactly as you posted:

Code: Select all

convert -size 200x200 pattern:checkerboard png24:cb.png

convert cb.png ( +clone +noise Random -virtual-pixel Gray -blur 0x8 ) -virtual-pixel Black -define compose:arg:5x5 -compose displace -composite cb_displaced.png
Last edited by Tagomago on 2011-02-24T11:48:59-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble compositing images onto effects-filled canvases

Post by fmw42 »

I get the same result as Anthony on my Mac OSX Tiger IM 6.6.7.9 Q16.
compose displace-composite cb_displaced.png
Note you have a missing space between display and -composite. It should be:

compose displace -composite cb_displaced.png
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Trouble compositing images onto effects-filled canvases

Post by Tagomago »

That was a mistake in copying the code; I ran it again with the space and got the same result as the image posted above.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble compositing images onto effects-filled canvases

Post by fmw42 »

Is your IM version up to date enough to use the -define compose:args:5x5 syntax? You can also try -set options:compose:args 5x5

Note args not arg in both cases: see http://www.imagemagick.org/script/compose.php
Tagomago
Posts: 36
Joined: 2011-02-10T09:55:33-07:00
Authentication code: 8675308

Re: Trouble compositing images onto effects-filled canvases

Post by Tagomago »

I've just discovered through comparison that several commands/scripts don't work on windows 7 64-bit, but do work on windows xp/vista 32-bit. So --- I've got to go through a retry several problems, including this one. If it still doesn't work, I'll try that method. Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Trouble compositing images onto effects-filled canvases

Post by anthony »

fmw42 wrote:Is your IM version up to date enough to use the -define compose:args:5x5 syntax? You can also try -set options:compose:args 5x5

Note args not arg in both cases: see http://www.imagemagick.org/script/compose.php
Also you need '=' EG: -define compose:args=5x5

Without the '=' you are defining an artifact named "compose:args:5x5" with a value of "" --- a -verbose info: output will list the artifacts that are defined.

ASIDE: -verbose is itself a shorthand for -define verbose operational setting :-)

See IM Examples, Defining Artifacts (special settings for coders and operators)
http://www.imagemagick.org/Usage/basics/#define


You can also use the equivalent -set option (watch that the space replaces the '=')... -set option:compose:args 5x5
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply