Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
-
volkan
- Posts: 8
- Joined: 2017-07-06T03:55:26-07:00
- Authentication code: 1151
Post
by volkan » 2017-07-13T00:46:46-07:00
Hello when i try to remove background my code is
Code: Select all
convert master.JPG back.JPG \( -clone 0 -clone 1 -compose difference -composite -threshold 0 \) \
-delete 1 -alpha off -compose copy_opacity -composite -fuzz 10% -transparent white -trim \
output.png
Master image
Background image
out image transparent
some of images close to white color so white areas maybe transparent some times, my code is good or any idea ?
-
snibgo
- Posts: 10022
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2017-07-13T04:25:13-07:00
That seems a very complex command. Where did back.JPG come from? If you made it, why is it jpeg? Never use jpeg, unless you really have to.
Why not simply:
Code: Select all
convert yellowJacket.jpg -fuzz 10% -transparent White out.png
10% is a wide margin. I usually find 5% is enough for finding a flat colour in a jpg. For clarity, I try things like this:
Code: Select all
convert yellowJacket.jpg -fuzz 5% -fill Red -opaque White x.png
Then I can easily see if the correct pixels have changed.
-
volkan
- Posts: 8
- Joined: 2017-07-06T03:55:26-07:00
- Authentication code: 1151
Post
by volkan » 2017-07-25T09:01:45-07:00
Hi
Thanks a lot , we actually use raw photo so my command looks like
this
Some images has a white areas in the object fuzz method not working very well
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-07-25T09:32:17-07:00
you can do a flood fill to only make the outside white areas transparent
Code: Select all
convert master.JPG -fuzz 5% -fill none -draw "matte 0,0 floodfill" result.png
Please always provide your IM version and platform, since syntax may vary.
-
volkan
- Posts: 8
- Joined: 2017-07-06T03:55:26-07:00
- Authentication code: 1151
Post
by volkan » 2017-07-25T09:56:21-07:00
Hi ,
Thanks for your help , My IM details
Code: Select all
Version: ImageMagick 7.0.6-3 Q16 x86_64 2017-07-24 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
Error happen
Code: Select all
convert: non-conforming drawing primitive definition `matte' @ error/draw.c/DrawImage/3269.
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-07-25T10:14:48-07:00
For IM 7, the syntax is slightly different.
Code: Select all
magick master.JPG -fuzz 5% -bordercolor white -border 1 -fill none -draw "alpha 0,0 floodfill" -shave 1x1 result.png
I have added a white border at the beginning so that the floodfill will work all around and between his legs. The shave off the border at the end.
But, note, that floodfill will skip processing the gap between his arms and his body and between his fingers. So you might have to floodfill those regions separately, if you want them transparent.
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-07-25T10:18:42-07:00
I have made an edit, so be sure to review above
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-07-25T10:43:10-07:00
Here is another way. You threshold the image to make white as black and all the rest as white to create a mask. Then remove small regions (less than 30 pixel area) using -connected-components. Then put the resulting processed mask into the alpha channel of the image.
See
http://magick.imagemagick.org/script/co ... onents.php
Code: Select all
convert master.jpeg \
\( -clone 0 -negate -threshold 5% -type bilevel +write master_mask_before.gif \
-define connected-components:area-threshold=30 \
-define connected-components:mean-color=true \
-connected-components 4 +write master_mask_after.gif \) \
-alpha off -compose copy_opacity -composite \
master_transparent.png
I have save the mask before and after processing and the result.
mask before:
mask after:
result:

-
volkan
- Posts: 8
- Joined: 2017-07-06T03:55:26-07:00
- Authentication code: 1151
Post
by volkan » 2017-07-26T06:14:29-07:00
Hi
very good method
it's amazing when i search the algorithms i found this
https://youtu.be/6uPj8qeMVJk?t=1m3s
I think use very different light methods to help background removal
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-07-26T09:21:35-07:00
-
volkan
- Posts: 8
- Joined: 2017-07-06T03:55:26-07:00
- Authentication code: 1151
Post
by volkan » 2017-08-08T16:16:29-07:00
Hello Again

)
Black Background image
White Background image
when i try to remove background result is :
if you look more carefully
can you see ?

)
Please focus on the product. product is %80 Transparent

-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-08-08T16:45:09-07:00
Which of your two input images (black background or white background) were you using the make your result above?
What was the command you used?
I have moved this topic to the Users forum, since you are using Imagemagick commands.
Try this:
Code: Select all
convert w.jpg -fuzz 25% -transparent white w_t.png
-
fmw42
- Posts: 22966
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2018-01-06T13:41:44-07:00
Your problem with your two images is that the black background one is not fully black near the label, whereas your white background one is more solidly white. In your black one, you can see dark gray close to the label.