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?".
User avatar
fmw42
Posts: 25562
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 »

I do not understand how your desired image is different from the one you created (even though you used the wrong size arguments). Can you explain in more detail how they differ and what exactly you expect
eimahendravala
Posts: 5
Joined: 2015-04-22T03:04:22-07:00
Authentication code: 6789

Re: How to overlay an Image on the base Image

Post by eimahendravala »

Hello fmw42,

Thanks.

I have worked on this but it is not sorted. Let me make it very simpler.

I have a plain sleeve http://tfy.info/im/sleeve_left.1.png. Where I am trying to apply fabric http://tfy.info/im/fabric.5.png on it. I am getting this http://tfy.info/im/sleeve_left.png as output by executing bellow commands:

convert fabric.5.png -rotate -27 -crop 720x400+210+210 fabric-rot.50.png
convert fabric.5.png -rotate 50 -crop 720x400+210+210 fabric-rot.60.png
convert fabric-rot.50.png fabric-rot.60.png -geometry +0+240 -composite sleeve_left_fabric.png
convert sleeve_left.1.png sleeve_left_fabric.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 sleeve_left.png

Which is very poor. I want to output as http://tfy.info/im/exp_sleeve_left.1.png.

Can u please help me for create proper command for the same.

Thanks - Mahendra
User avatar
fmw42
Posts: 25562
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 »

Your two images should be the same size and the sizes used in the commands should correspond. Your two images are not detail enough to support the detail you want for your result.

You can try trimming your sleeve image and resizing the texture images (with sharpening) to the same size. The process and then insert the result into a transparent image at the same location as the sleeve was trimmed.

Alternately, make higher resolution images for both.
eimahendravala
Posts: 5
Joined: 2015-04-22T03:04:22-07:00
Authentication code: 6789

Re: How to overlay an Image on the base Image

Post by eimahendravala »

Hello fmw42,

I have created the collar images for my tailor store with this bellow method. Every thing is going great but the images created with this way became very heavy approx of 500 to 600 kbs which takes much time while loading, is there any way to make it lighter.

Thank you very much.
- eimahendravala
fmw42 wrote: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
User avatar
fmw42
Posts: 25562
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 »

Only thing I can think of is to make this one long command line using clones and parenthesis processing, so you do not waste time writing all the intermediate images. That should make the processing faster, but I do not know about the file sizes. Perhaps at the end write to PNG8:.

See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to overlay an Image on the base Image

Post by snibgo »

If the image is "noisy" like a photograph, the default quality for PNG gives a filesize about 75% of uncompressed, and is about as good as it gets. A non-compressed TIFF is probably faster to read and write. Even better, uncompressed MIFF or MPC.

If the image contains mostly flat colours, the default PNG can be made smaller, eg with "-quality 80".

If the very smallest PNG is desired, the "pngcrush" program is useful.
snibgo's IM pages: im.snibgo.com
hiren
Posts: 6
Joined: 2015-07-11T12:43:39-07:00
Authentication code: 1151

Re: How to overlay an Image on the base Image

Post by hiren »

Hello,

I tried follow the commands in previous post I read. But I am not getting my expected result.
Can anyone help?

Here is my fabric.
Image

I apply the following commands and make fabric image which I am going to apply on my shirt sleeves.

Code: Select all

convert -size 600x600 tile:fabric.jpg fab_red_new.png

convert fab_red_new.png -rotate 20 -gravity southeast -extent 1200x1200-600-590 -transparent white fabric-sleeves-left-top.png
convert fab_red_new.png -rotate -39 -gravity southeast  -extent 1200x1200-600-0 -transparent white fabric-sleeves-left-bottom.png
convert fabric-sleeves-left-bottom.png fabric-sleeves-left-top.png -geometry 1200X1200+0+0 -composite -transparent white sleeve_left_fabric.png

convert fab_red_new.png -rotate -20 -gravity southwest  -extent 1200x1200-600-590 -transparent white fabric-sleeves-right-top.png
convert fab_red_new.png -rotate 15 -gravity southwest  -extent 1200x1200-600-0 -transparent white fabric-sleeves-right-bottom.png
convert fabric-sleeves-right-bottom.png fabric-sleeves-right-top.png -geometry 1200X1200+0+0 -composite -transparent white sleeves_right_fabric.png

convert sleeve_left_fabric.png sleeves_right_fabric.png -geometry 1200X1200+0+0 -composite -transparent white sleeve_full_fabric.png
This will generate my fabric image as follow.
Image

After generate my fabric image I am going to apply overlay to my shirt sleeves using following command.

Code: Select all

convert shirt_sleeve_full_front.png sleeve_full_fabric.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 sleeve_full.png
And I am getting following output.
Image

But this is my expected result.
Image

Sleeves fabric is going to cut from elbow in my current result.
What should I do to get my expected result?

Thanks.
User avatar
fmw42
Posts: 25562
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 »

What version of IM and what platform? Post your sleeve image before applying the pattern (shirt_sleeve_full_front.png). It may be too dark after the auto-level. How did you create the "correct" result image?

Does this work better?

Code: Select all

convert shirt_sleeve_full_front.png sleeve_full_fabric.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 +swap -compose hardlight -composite sleeve_full.png
hiren
Posts: 6
Joined: 2015-07-11T12:43:39-07:00
Authentication code: 1151

Re: How to overlay an Image on the base Image

Post by hiren »

Thanks for reply fmw42.

Here is my shirt_sleeve_full_front.png
Image


I am getting following result with "hardlight"
Image
hiren
Posts: 6
Joined: 2015-07-11T12:43:39-07:00
Authentication code: 1151

Re: How to overlay an Image on the base Image

Post by hiren »

Sorry I forgot to wrote the version of IM and platform.

I am using,

ImageMagick 6.8.9-1
Mac OS 10.8.5
User avatar
fmw42
Posts: 25562
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 »

Your white shirt sleeves are too gray, so the multiply is darkening them by the gray. Try multiplying the shirt sleeve image by a factor of about 1.1 as

Code: Select all

convert \( shirt_sleeve_full_front.png -auto-level -evaluate multiply 1.1 \) sleeve_full_fabric.png \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace -set option:compose:args -5x-5 -composite \) \
-delete 1 -compose multiply -composite sleeve_full.png
Adjust the (1.1) factor to give a pleasing result to you. Note you do not need the extra clone to do the auto-level.



Alternately, compute the mean of the shirtsleeve image and adjust it to 50% (0.5 in the range of 0 to 1). Compute the factor needed to do this. Then adjust the contrast to make the darks darker and the lights lighter while keeping the mean at 50%

Code: Select all

fact=`convert shirt_sleeve_full_front.png -auto-level -scale 1x1! -format "%[fx:0.5/mean]" info:`
convert \( shirt_sleeve_full_front.png -auto-level -evaluate multiply $fact -sigmoidal-contrast 10x50% \) sleeve_full_fabric.png \
\( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace -set option:compose:args -5x-5 -composite \) \
-delete 1 -compose hardlight -composite sleeve_full.png
Adjust the first sigmoidal-contrast value (10) to make the result pleasing to you.
hiren
Posts: 6
Joined: 2015-07-11T12:43:39-07:00
Authentication code: 1151

Re: How to overlay an Image on the base Image

Post by hiren »

Thanks fmw42,

But how can I merge the shirt elbow fabric?

Image

It is not looking proper.
User avatar
fmw42
Posts: 25562
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 »

that is because your texture image is not continuous. I do not know how you can fix it apart from my comments and commands earlier in the post to bend the one striped image.
User avatar
fmw42
Posts: 25562
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 »

You could try to align the rotated striped images better and then smooth over the seem.
hiren
Posts: 6
Joined: 2015-07-11T12:43:39-07:00
Authentication code: 1151

Re: How to overlay an Image on the base Image

Post by hiren »

Yes I also saw that post and tried to apply it on my example. But it is not working.
I think it is working with non-transparent images.
Post Reply