Background Removal with Image patter

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Locked
pedromtorres
Posts: 3
Joined: 2016-01-12T14:56:20-07:00
Authentication code: 1151

Background Removal with Image patter

Post 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?

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

Re: Background Removal with Image patter

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

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

Re: Background Removal with Image patter

Post 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/

pedromtorres
Posts: 3
Joined: 2016-01-12T14:56:20-07:00
Authentication code: 1151

Re: Background Removal with Image patter

Post 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 :)

pedromtorres
Posts: 3
Joined: 2016-01-12T14:56:20-07:00
Authentication code: 1151

Re: Background Removal with Image patter

Post 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.

Locked