Ask Your Question

Problem in removing particular colors from the given image

asked 2016-02-04 08:46:44 -0600

Dr Dre gravatar image

updated 2016-02-04 10:12:24 -0600

Hi Guys I have the following image

Input Image

I want to know if there is any method which basically removes black and blue box from the image and the final image contains only orange , green pink and light blue box i.e. I want my output image to be displayed as

Output Image

I am using python 2.7 with cv2


Following the suggestion give by @StevenPuttemans

I converted my given image to HSV using following code

img = cv2.imread('Image.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

I got output as

Intermediate Output

What procedure should i follow next to get my output as shown in 2nd image.

edit retag flag offensive close merge delete


Convert your images to a color space where those black and blue colors are seperable from the others. As a first guess, HSV could already do the trick!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-04 09:05:37 -0600 )edit

What procedure should i follow next sir @StevenPuttemans

Dr Dre gravatar imageDr Dre ( 2016-02-04 10:13:13 -0600 )edit

Well, you need to find a function (or two) that results in a true value where the colors you are removing are, and false in the rest. Take a look at the pixel values for the colors you wish to remove. How are they different from the other colors? Is one value (of the 3) always lower or always higher? Then that's a good way to tell the difference. The threshold or bitwise functions can help turn that into a mask.

Tetragramm gravatar imageTetragramm ( 2016-02-04 16:33:04 -0600 )edit

Start by splitting up into channels, then take a look at the HSV channel properties and like @Tetragramm said, try to define ranges which apply for your seperation boundary.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-05 04:16:36 -0600 )edit

Thank U Guys

Dr Dre gravatar imageDr Dre ( 2016-02-05 11:27:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-06 08:49:07 -0600

Dr Dre gravatar image

updated 2016-02-06 08:57:06 -0600

I Filtered out only sky blue color, Pink Color, Orange and Green Color using masking function separetely and added the images to get an image containing only the 4 colors

then by converting bgr to gray and thresholding i could draw the contours

Thank U Every one for ur help and support

image description

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-02-04 08:46:44 -0600

Seen: 5,013 times

Last updated: Feb 06 '16