Re: Applying Logo To Shirt (white halo)
Posted: 2014-05-18T13:14:10-07:00
Here is how I would do it step by step. You can combine these into one command if you want.
# create shirt mask

# insert picture in transparent background at correct location for placement on shirt

# extract picture mask

# apply shirt mask to shirt and get mean of opaque only area
# process tshirt to make sure shirt area is close to mean=0.5 and background is mid gray

# create lighting mask --
# you can include some kind of contrast adjustment here if you want to make the lighting effect stronger,
# but keep the mean close to 0.5 (e.g. -level 10x90% or -sigmoidal-contrast 2x50%)
# also add blur if you want less texture to show from shirt in the picture

# create displacement map -- blur to make it smooth so texture does not cause jagged offsets

# apply lighting to picture using -compose hardlight and put back alpha channel

# apply displacement map to lighted picture

# apply displaced picture over tshirt and apply shirt mask

# create shirt mask
Code: Select all
convert shirt.jpg -threshold 40% -negate shirt_mask.png

# insert picture in transparent background at correct location for placement on shirt
Code: Select all
convert \( shirt.jpg -alpha transparent \) picture.png -geometry +313+192 -composite picture_trans.png

# extract picture mask
Code: Select all
convert picture_trans.png -alpha extract picture_mask.png

# apply shirt mask to shirt and get mean of opaque only area
Code: Select all
convert shirt.jpg shirt_mask.png -alpha off -compose copy_opacity -composite -scale 1x1! -format "%[fx:mean]" info:
0.206912
Code: Select all
convert shirt.jpg shirt_mask.png -alpha off -compose copy_opacity -composite -evaluate add 30% \
-alpha on -background "gray(50%)" -alpha background -alpha off tshirt_process.png

# create lighting mask --
# you can include some kind of contrast adjustment here if you want to make the lighting effect stronger,
# but keep the mean close to 0.5 (e.g. -level 10x90% or -sigmoidal-contrast 2x50%)
# also add blur if you want less texture to show from shirt in the picture
Code: Select all
convert tshirt_process.png lighting.png

# create displacement map -- blur to make it smooth so texture does not cause jagged offsets
Code: Select all
convert tshirt_process.png -blur 0x2 displacement.png

# apply lighting to picture using -compose hardlight and put back alpha channel
Code: Select all
convert picture_trans.png lighting.png -compose hardlight -composite \
picture_mask.png -compose over -compose copy_opacity -composite picture_light.png

# apply displacement map to lighted picture
Code: Select all
convert picture_light.png displacement.png -define compose:args=-20,-20 \
-compose over -compose displace -composite picture_light_displace.png

# apply displaced picture over tshirt and apply shirt mask
Code: Select all
convert shirt.jpg picture_light_displace.png -compose over -composite \
shirt_mask.png -alpha off -compose copy_opacity -composite shirt_picture.png
