imagmgick multiple color and transparent image with anti aliasing

641 Views Asked by At

Original Image:

enter image description here

and this what needs to be achieved. enter image description here

brick image: enter image description here

I have many images like one below

enter image description here

I need to multiply this image with a color say "rgba(103,68,56,5)" and make the center white part transparent.

The way I do:

convert mortar.png ( -clone 0 -fill 'rgba(103,68,56,5)' -colorize 100 ) -channel rgba -alpha on -compose Multiply -composite mortar.png

convert mortar.png -transparent 'rgba(103,68,56,5)' mortar.png

the resultant image I get is:

enter image description here

Where as desired image is something like one below: Just look at the inside corner line of the image and the dots on white area you can ignore.

enter image description here

I have tried with different fuzz values as well but that degrades the image more and put holes in the colored area.

Please right click the image and save it at your location to see what full image looks like.

Output after adding blur with command

convert m.png -blur 0x.3 ( +clone -fill 'rgba(103,68,56,5)' -colorize 100 ) -channel rgba -alpha on -compose Multiply -composite -transparent 'rgba(103,68,56,5)' out.png

enter image description here

Desired output:

enter image description here

1

There are 1 best solutions below

3
On

Updated Answer

I think the problem is that your original mortar image is already noisy around the borders. I took it into Photoshop and enlarged it a lot and you can see that it has noisy artefacts around the edges.

enter image description here

I can only think of blurring these and then thresholding them up to pure white, because some of the noisy bits actually also occur in the real borders where you don't want them to go transparent. I am thinking along these lines:

convert mortar.png -blur 0x3 -white-threshold 95% -transparent white \( +clone -fill 'rgb(103,68,56)' -colorize 100 \) -compose Multiply -composite out.png

Not sure what else to suggest.

Original Answer

I think you might find it useful to add a tiny amount of blur to help the edges, and also do it all in one go like this:

convert mortar.png -blur 0x.3 \( +clone -fill 'rgba(103,68,56,5)' -colorize 100 \) -channel rgba -alpha on -compose Multiply -composite -transparent 'rgba(103,68,56,5)'  out.png