Skip to content
Advertisement

Add texture of img1 to img2 to get result img – Python / Javascript

I am trying to add texture and pattern of img1 to img2 to get result something like the result image img3 – Img2 is has transparent background and result Img3 must also have transparent background

Img1

Img2

Img3


Advertisement

Answer

Here is how to do that in Imagemagick. It can be done in Python/OpenCV, but I do not have the time now to implement it. It is pretty easy in Imagemagick using one of my bash shell scripts to do the spherize of the texture.

(I show how to do the spherical distortion in Python/OpenCV at How make eye and nose bigger or smaller in opencv and python in a previous post. And an example showing how to do the hard light composite in Python/OpenCV is in How to augment scanned document image with creases, folds and wrinkles?)

  • First, I have to trim the sphere image to its bounds and have it square dimensions.
  • Then I have to resize the texture image and crop it to the same dimensions as the trimmed sphere image.
  • Then I apply the spherize script to the cropped texture image
  • Finally I save the alpha channel from the sphere image and do a hardlight composite of the sphere image with the spherized texture image. And save the result

Sphere Image:

enter image description here

Texture Image:

enter image description here

convert sphere.png -trim +repage sphere_trim.png

convert texture.jpg -resize 1375x1375^ -gravity center -crop 1375x1375+0+0 +repage texture_resize_crop.jpg

spherize -a 1 -b white texture_resize_crop.jpg texture_resize_crop_spherize_a1.jpg

convert texture_resize_crop_spherize_a1.jpg 
sphere_trim.png 
( +clone -alpha extract +write mpr:alpha +delete ) -alpha off 
( +clone ) 
-compose hardlight -composite 
mpr:alpha -alpha off -compose over -compose copy_opacity -composite 
sphere_texture.png

Trimmed Sphere Image:

enter image description here

Resized and Cropped Texture Image:

enter image description here

Spherized Texture Image:

enter image description here

Result From Hardlight Composite:

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement