How to overlay an Image on the base Image

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?".
mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

How to overlay an Image on the base Image

Post by mahak2050 » 2013-05-05T02:07:59-07:00

Hi,

I need help on the this.
I specify the path of the required Images.

I have a fabric Image and a base Image and I want it to make or want to shape something like Image.
But I am not getting the exect output. Will you please let me know where I am doing wrong.
Please Let me know the correct syntax or commands.

Required Images :
Base Image :
======================================================================================
Image
Fabric Image :
======================================================================================
Image
Output Image( But this is not what I want ) :
======================================================================================
Image
I want which is similer to this:
======================================================================================
Image
======================================================================================


Below are the commands which I am executing to achive this.

convert 769_main_set2_0000.png -background black -alpha background black_769_main_set2_0000.png

convert 1_full_shirt_swatch.png \( black_769_main_set2_0000.png -blur "0x2" -auto-level \) -alpha set -virtual-pixel transparent -compose displace -set option:compose:args "-7x-7" -composite displace_769_main_set2_0000.png

convert displace_769_main_set2_0000.png black_769_main_set2_0000.png -compose multiply -composite 1_main_set2_0000.png

Thanks
Mahak

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2013-05-05T11:56:14-07:00

I suspect you got no answer because no one understood what the issue was. It had looked like you got an appropriate result.

However, you command lines looks rather strange to me.

see
viewtopic.php?f=1&t=20455&hilit=distort+hard&start=30


try this (I renamed your images so I could tell which was which):

Image

Image


convert sleeves.png pattern.png \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern.png

Image

mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: How to overlay an Image on the base Image

Post by mahak2050 » 2013-05-05T20:18:32-07:00

Thanks Fred,

But My problem is :

If you see the desired output Image http://dappermen.com/media/swatches/100 ... 2_0000.png In this Image the lines are slightly inclined on the right ( like / ) at top and again slightly inclined on left ( like \ ) at bottom of the sleeve image. So I want that effect, Is that possible or some other logic to get this.

Because In our output Image the lines are just vertical. see http://dappermen.com/media/swatches/shi ... 2_0000.png
Let me know If you got my point or should I explain more on this.

Thanks
Mahak

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to overlay an Image on the base Image

Post by anthony » 2013-05-05T22:02:47-07:00

You will need a separate 'displacement/distortion' map to the shading image, though they are probably related.

How to create a displacement map from the 'pinstripe lines) image is a tricky matter, and using the images given only a sideways displacement can possibly be worked out.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2013-05-05T22:07:23-07:00

Best I can do this evening is to create a diamond shaped gradient and use -compose distort (see http://www.imagemagick.org/script/compose.php), which unfortunately distorts in a radial direction, so the lines will get somewhat curved. The diamond shaped gradient is created by solarizing a horizontal gradient, making a 90 degree rotated version and then multiplying the two solarized gradients. You would need to do this and then apply the previous distortion to get the bends and the folds. But this will give you ideas. To do it right you will need to do a diamond shaped absolute displacement (properly centered so that it splits at the elbows and not the center of the image). But that you would have to build using -fx. see http://www.imagemagick.org/Usage/mappin ... rtion_maps



convert sleeves.png pattern.png \
\( -clone 0 -alpha extract \) \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 3 -rotate 90 \) \
\( -clone 3 -clone 4 -compose multiply -composite -negate -scale 440x600! \
-clone 2 -alpha off -compose over -compose copy_opacity -composite \) \
-delete 0,2,3,4 -alpha set -virtual-pixel transparent -compose distort \
-set option:compose:args 200x200+220+300 -composite sleeves_pattern_distort.png


Image

mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: How to overlay an Image on the base Image

Post by mahak2050 » 2013-05-05T22:52:20-07:00

Thank you!

But as you see the previous shrink effect removed from the output image I need those effect too.

Thanks
Mahak

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2013-05-05T22:57:26-07:00

I said you need to apply this distortion and then follow it with the other distortion as I showed above. You need to do two separate distortions. You will need to do them separately in two command lines or combine them all into one command line.

Here is a better version of the current distortion. I created the diamond shaped gradient and then negate the right side so that -compose displace can be used in place of the radial -compose distort. This keeps the lines straight so they don't curve.


convert sleeves.png pattern.png \
\( -clone 0 -alpha extract \) \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 3 -rotate 90 \) \
\( -clone 3 -clone 4 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 5 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 5 -clone 6 -clone 7 -compose over -composite \
-clone 2 -alpha off -compose over -compose copy_opacity -composite \) \
-delete 0,2,3,4,5,6,7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite sleeves_pattern_displace.png

Image

After this you need to apply the earlier displacement using this resulting image as the input rather than the pattern image. You may need to remove the alpha channel first.

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2013-05-05T23:28:38-07:00

Here it is all put together. I probably cannot improve this any more.

I have shifted the diamond gradient down a litte, so that its center is even with the elbows.


convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
-delete 0,2,3,4,5,6, -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite sleeves_pattern_displace.png

convert sleeves.png sleeves_pattern_displace.png \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice.png


Here I have combined the two commands into one command

convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite \) \
-delete 1-7 \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice.png


Image

mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: How to overlay an Image on the base Image

Post by mahak2050 » 2013-05-06T11:41:49-07:00

Thanks for you support.
But If you noticed that the stripes are blured or strached ( i mean they lost their smoothness )
Please let me know If there is any other chance to improvisation.
Or let me know where I can make the changes in the command So that I can make some iterations at my end to get better output.

But I appreciate you really helped me. Thanks again.
Mahak

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2013-05-06T13:12:01-07:00

Try this. You can play with the parameters marked in blue. However, by decreasing them as I have done, it makes the lines less distorted and more straight. Some of blurriness is a limitation of the IM displace function having limited anti-aliasing in its resampling and there is no current ability to adjust it as far as I know. I replaced the two -scale functions with the better -resize (see the red). That helps fix much of the blurriness.


convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -resize 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -resize 300% -gravity center -crop 440x600+0-30 +repage \) \
\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite \) \
-delete 1,2,3,4,5,6,7 \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice_b.png

Image


If I change -100x-100 to -50x-50, it helps a little but makes the bending at the elbows less and the lines are a little further apart.

Image

From here, you will have to just try different arguments. I really do not know how to improve it any further.

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to overlay an Image on the base Image

Post by anthony » 2013-05-06T19:02:25-07:00

Now that you have a technique, run it on a greyscale gradient, and generate a absolute distortion map for that set of arms.

Then that distortion map can be converted to a displacement map (if wanted).

that will simplify ans speed up the the running process for any 'vertically striped' fabric, for that overlay.

The map, shading and mask, can all be stored in a single image..
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to overlay an Image on the base Image

Post by anthony » 2014-04-03T16:01:59-07:00

You will need to generate a distortion map with the rotations you want on each side of the collar. and at the back.

I would start with working out the mapping for some specific points, then smooth the X,Y image maps around those points.

Alternativally, get a 'collar pattern' from a dress makers plan, and use that to determine source coordinates (on the texture. While using your final image to determine the destination coordinates for the same points. Preferably at a larger scale, so that you get good anti-aliasing by shrinking the image after the distortion mapping.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2014-04-03T16:14:19-07:00

Here is rather awkward way to do it. But it is certainly one way if you do not have a good high quality new pattern. I have outlined the steps one by one, but you can combine many of the steps into one long command line.


# manually crop out a piece of the old collar (and with trial an error make it tileable)
Image

# tile this piece to twice the size of the whole collar image
convert -size 880x1200 tile:old_stripe_sub.png old_stripe_tile.png
http://www.fmwconcepts.com/misc_tests/c ... e_tile.png

# rotate the tiled image by +45 and -45 degrees
convert old_stripe_tile.png -rotate 45 +repage -gravity center -crop 440x600+0+0 +repage old_stripe_tile_r45.png
convert old_stripe_tile.png -rotate -45 +repage -gravity center -crop 440x600+0+0 +repage old_stripe_tile_rm45.png
http://www.fmwconcepts.com/misc_tests/c ... le_r45.png
http://www.fmwconcepts.com/misc_tests/c ... e_rm45.png

# extract the alpha channel of the original collar image
convert old_collar.png -alpha extract collar_mask.png
http://www.fmwconcepts.com/misc_tests/c ... r_mask.png

# split the mask along the vertical line going through the gap in the two sides of the collar
convert collar_mask.png[247x600+0+0] collar_mask_left.png
convert collar_mask.png[+248+0] collar_mask_right.png
http://www.fmwconcepts.com/misc_tests/c ... k_left.png
http://www.fmwconcepts.com/misc_tests/c ... _right.png

# use each mask on the corresponding rotated tiled image of the same subsection size as the mask
convert old_stripe_tile_rm45.png[247x600+0+0] collar_mask_left.png -alpha off -compose copy_opacity -composite collar_left.png
convert old_stripe_tile_r45.png[+248+0] collar_mask_right.png -alpha off -compose copy_opacity -composite collar_right.png
http://www.fmwconcepts.com/misc_tests/c ... r_left.png
http://www.fmwconcepts.com/misc_tests/c ... _right.png

# append the two results above together to make the final processed new collar
convert collar_left.png collar_right.png +append new_collar_proc.png
http://www.fmwconcepts.com/misc_tests/c ... r_proc.png

pratik123
Posts: 10
Joined: 2014-04-07T03:35:04-07:00
Authentication code: 6789

Re: How to overlay an Image on the base Image

Post by pratik123 » 2014-04-13T22:43:40-07:00

fmw42 wrote:Here it is all put together. I probably cannot improve this any more.

I have shifted the diamond gradient down a litte, so that its center is even with the elbows.


convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
-delete 0,2,3,4,5,6, -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite sleeves_pattern_displace.png

convert sleeves.png sleeves_pattern_displace.png \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice.png


Here I have combined the two commands into one command

convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite \) \
-delete 1-7 \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern_displace_twice.png


Image
hi
i am using this code
its generate wrong image please see
http://oi60.tinypic.com/md39ec.jpg

i am using following code
convert sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite \) \
-delete 1-7 \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern21_displace_twice.png

Can you please tell me its version problem ya anything else.

Thank you

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

Re: How to overlay an Image on the base Image

Post by fmw42 » 2014-04-13T22:50:18-07:00

what version of IM are you using?

try adding -respect-parenthesis

Code: Select all

convert -respect-parenthesis sleeves.png pattern.png \
\( -size 440x440 gradient: -solarize 50% -level 0x50% \) \
\( -clone 2 -rotate 90 \) \
\( -clone 2 -clone 3 -compose multiply -composite -negate -scale 440x600! \) \
\( -clone 4 -negate \) \
\( -size 600x440 gradient: -rotate 90 -set colorspace RGB -threshold 50% \) \
\( -clone 4 -clone 5 -clone 6 -compose over -composite -scale 300% -gravity center -crop 440x600+0-30 +repage \) \
\( -clone 1 -clone 7 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -100x-100 -composite \) \
-delete 1-7 \
\( -clone 0 -auto-level \) \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace \
-set option:compose:args -5x-5 -composite \) \
-delete 0,1 -compose multiply -composite sleeves_pattern21_displace_twice.png

Post Reply