Ask Your Question
1

Remove buttons from their background so I can re-use button image

asked 2012-10-14 23:16:38 -0600

Philip gravatar image

updated 2012-10-15 00:21:02 -0600

How to use OpenCV (Python script) to remove the background from these button images so that only the button remains? I wish to be able to re-use the button image to place it onto a different background and not sure what OpenCV methods to use. Here are some example button images:

image description

image description

image description

Here is a zip file with many button images to try: http://www.orsa-studio.com/buttons.zip

Note that buttons have the following properties.

  1. Their background may not be completely flat with one color, it may be a pattern or a gradient.
  2. They have a corner, the corner may have a radius or it may be square.
  3. The button will take up most of the image, at least more than 1/2 the width and height of the image.
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-10-15 03:34:17 -0600

Kirill Kornyakov gravatar image

I think you should start with findContours. Here are a lot of tutorials for similar tasks, especially this two 1, 2.

When you know (at least approximate) contour of a button, you can cut slightly larger area and then remove background pixels (set transparency). As you mentioned, you can easily detect background color, so it can be masked later. To generate such mask, convert your image to HSV and use inRange function.

edit flag offensive delete link more

Comments

I'll try this tomorrow and let you know how it goes.

Philip gravatar imagePhilip ( 2012-10-17 22:35:35 -0600 )edit

I used grabCut after the findContours and this seems to work well in about 75% of cases, I have not fine tuned it by altering parameters yet. In most cases where it is not working its due to the findContours and associate code not finding the bounding rectangle correctly.

Philip gravatar imagePhilip ( 2012-10-26 09:51:58 -0600 )edit

Question Tools

Stats

Asked: 2012-10-14 23:16:38 -0600

Seen: 756 times

Last updated: Oct 15 '12