Page 1 of 1

Background Removal with Image patter

Posted: 2016-01-12T15:16:56-07:00
by pedromtorres
Hello,
I am trying to remove the background of my suppliers products. He takes pictures with a studio showing his brand and contacts, which i can't show in my e-store.
I need to blur all the background including his logos and all the text he displays.

His images look like this:
Image
Image

and should end up like this:
Image

this is the code i am using:

Code: Select all

convert ${IMGPATH}${IMGNAME} \( +clone -fx 'p{0,0}' \)  -compose Difference  -composite -fuzz 15%  -modulate 100,10  +matte ${IMGPATH}${IMGNAME}_difference.png

convert ${IMGPATH}${IMGNAME}_difference.png -bordercolor white -border 1x1 -matte -fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 ${IMGPATH}${IMGNAME}_removed_black.png
composite  -compose Dst_Over -tile pattern:checkerboard ${IMGPATH}${IMGNAME}_removed_black.png ${IMGPATH}${IMGNAME}_removed_black_check.png

convert ${IMGPATH}${IMGNAME}_removed_black.png -channel matte -separate  +matte ${IMGPATH}${IMGNAME}_matte.png

convert ${IMGPATH}${IMGNAME}_matte.png -negate -blur 0x1 ${IMGPATH}${IMGNAME}_matte-negated.png
convert ${IMGPATH}${IMGNAME}_matte.png -morphology Erode Diamond ${IMGPATH}${IMGNAME}_erode_matte.png
composite -compose CopyOpacity ${IMGPATH}${IMGNAME}_erode_matte.png ${IMGPATH}${IMGNAME} ${IMGPATH}${IMGNAME}_finished.png
convert ${IMGPATH}${IMGNAME}_finished.png -bordercolor white -border 1x1 -matte -fill none -fuzz ${THRESHOLD}% -draw 'matte 1,1 floodfill' -shave 1x1 ${IMGPATH}${IMGNAME}_final.png
and i'm obtaining this:
Image

The program is having difficult with the logos and shadows. The shadows are not trouble as the intention is to blur the background in the end so it won't be that noticable. but the logos are my problem.

Any help how to find blur the logos?

Re: Background Removal with Image patter

Posted: 2016-01-12T15:30:29-07:00
by snibgo
It seems your supplier has deliberately taken the photos so you couldn't easily do what you want to do.

The obvious solution is to ask your supplier to provide photos with plain backgrounds. Why can't you do that?

Re: Background Removal with Image patter

Posted: 2016-01-12T18:03:42-07:00
by fmw42
Background removal is very difficult when the background is not nearly a constant color. With some interactive drawing you can do it with graph cut tools. See https://clippingmagic.com/

Re: Background Removal with Image patter

Posted: 2016-01-13T02:53:31-07:00
by pedromtorres
snibgo wrote:It seems your supplier has deliberately taken the photos so you couldn't easily do what you want to do.

The obvious solution is to ask your supplier to provide photos with plain backgrounds. Why can't you do that?

He took all the photos in the past with his studio in the back. Now i'm selling his products in my store but can't do that with that background. He won't take 30.000 photos all over again and the replicate the process for every product inserted.

We also have his consent for this :)

Re: Background Removal with Image patter

Posted: 2016-01-13T02:58:11-07:00
by pedromtorres
fmw42 wrote:Background removal is very difficult when the background is not nearly a constant color. With some interactive drawing you can do it with graph cut tools. See https://clippingmagic.com/
I need the process to be almost 100% automatic. I had a person on a freelance site to do this for us. The quality was good but it took to much time.