Page 1 of 1
Fill transparent/white with an image
Posted: 2019-03-25T06:31:28-07:00
by crashxw
Hi everyone,
I have an image with white or transparent parts inside. What I want to achieve is to fill it with another image. That can happen multiple times because my image is a container of products and I need to merge these image with imagemagick
Do I need to compute the position then layer both images or is there a simplier way to do this ?
Thanks !
Re: Fill transparent/white with an image
Posted: 2019-03-25T07:47:16-07:00
by crashxw
So I did work on this subject and now I really know what I want to do
I try to get the white part of my image and I try to use connected-components
I did the following command :
convert t_container_1.png -threshold 10% -define connected-components:verbose=true -connected-components 8 test_connected.png
But the result is this :
Objects (id: bounding-box centroid area mean-color):
0: 2655x1009+0+0 1327.0,504.0 2678895 srgba(255,255,255,1.02446)
I need 3 shape with x and y positions to layer another image inside it
Any help why this command doesn't return the 3 white shapes of my image ?
EDIT
To help you here is a screenshot of what I try to do
https://imgur.com/3ngLvHU
I need to detect the 3 white shapes then add other images to fill them
Re: Fill transparent/white with an image
Posted: 2019-03-25T09:54:44-07:00
by snibgo
What version of IM? On what platform?
I don't understand your problem. Please show sample images.
Re: Fill transparent/white with an image
Posted: 2019-03-25T10:08:50-07:00
by fmw42
Please provide actual input images, not screenshots. Then explain exactly what you want to get for a result.
Re: Fill transparent/white with an image
Posted: 2019-03-26T01:41:00-07:00
by crashxw
Version: Version: ImageMagick 7.0.8-34 Q16
Platform: Mac os x
Input image:
1.
https://imgur.com/0N1fuAl
I want to get the positions of the 3 holes in the first image.
After getting positions I will fill it with another image
Thanks for your time, I hope it's ok now
Re: Fill transparent/white with an image
Posted: 2019-03-26T08:16:37-07:00
by snibgo
Code: Select all
magick 0N1fuAl.png +repage -background Black -layers Flatten -alpha off -channel RGB -threshold 10% +threshold -define connected-components:verbose=true -define connected-components:area-threshold=10000 -connected-components 8 x.png
Objects (id: bounding-box centroid area mean-color):
1: 1328x505+0+0 664.0,252.4 358174 srgb(255,255,255)
17: 328x328+914+89 1077.5,253.0 104487 srgb(0,0,0)
16: 328x328+498+88 661.6,251.4 104143 srgb(0,0,0)
10: 326x329+84+86 246.9,250.2 103836 srgb(0,0,0)
This gives the bounding boxes of the overall image (white) and the three large black areas.
Re: Fill transparent/white with an image
Posted: 2019-03-29T05:54:09-07:00
by crashxw
Thanks man