Fill transparent/white with an image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
crashxw
Posts: 4
Joined: 2019-03-25T06:25:34-07:00
Authentication code: 1152

Fill transparent/white with an image

Post by crashxw » 2019-03-25T06:31:28-07:00

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 !

crashxw
Posts: 4
Joined: 2019-03-25T06:25:34-07:00
Authentication code: 1152

Re: Fill transparent/white with an image

Post by crashxw » 2019-03-25T07:47:16-07:00

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

snibgo
Posts: 11796
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fill transparent/white with an image

Post by snibgo » 2019-03-25T09:54:44-07:00

What version of IM? On what platform?

I don't understand your problem. Please show sample images.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25123
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fill transparent/white with an image

Post by fmw42 » 2019-03-25T10:08:50-07:00

Please provide actual input images, not screenshots. Then explain exactly what you want to get for a result.

crashxw
Posts: 4
Joined: 2019-03-25T06:25:34-07:00
Authentication code: 1152

Re: Fill transparent/white with an image

Post by crashxw » 2019-03-26T01:41:00-07:00

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

snibgo
Posts: 11796
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fill transparent/white with an image

Post by snibgo » 2019-03-26T08:16:37-07:00

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.
snibgo's IM pages: im.snibgo.com

crashxw
Posts: 4
Joined: 2019-03-25T06:25:34-07:00
Authentication code: 1152

Re: Fill transparent/white with an image

Post by crashxw » 2019-03-29T05:54:09-07:00

Thanks man ;)

Post Reply