1

I am trying to pull all the pixels from the image on the right that are part of the shoe. I decided to take the edge detection of the image, but now I need to make a mask so that I can grab all the pixels bounded by the outer outline of the shoe. Is there a way in opencv to do this? I looked at the findContours function, but that only gave me a bunch of contours with no way to then make a mask?

enter image description here

2
  • 2
    finContours -> take largest -> floodfill Commented Aug 22, 2014 at 6:10
  • instead of floodfill you could drawContour filled (external contour only). Commented Aug 22, 2014 at 12:58

1 Answer 1

2

If floodfill does not provide you with a sufficient mask, another way could be to take the edge image from figure 1 and apply a dilation operator and then a closing operator. The mask will be slightly larger than the original due to the dilation although the dilation helps in closing black spots when applying the closing operator.

This is the result I obtained (I do not have a high enough rep to post the image in the answer. Here is the link): http://tinypic.com/view.php?pic=33jmpao&s=8#.U_cHm_mSz9s

The link below may also be useful to you. http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html

The code I used:

// Dilation Mat se = getStructuringElement(CV_SHAPE_ELLIPSE, Size(9, 9)); dilate(edge_image, dst, se, Point(-1,-1), 1); // Closing Mat closed; Mat element = getStructuringElement(MORPH_ELLIPSE, Size(19, 19)); morphologyEx(dst, closed, MORPH_CLOSE, element, Point(-1,-1), 3); 

This is my first answer on stackoverflow. I hope it helps and good luck! :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! What is Size(9,9) doing, and is it in the Python opencv? It looks like its a java thing, also what is dst and se?
This is OpenCV C++ code. You can find the python version in the second link in my original answer. Size(9,9) and Size(19,19) specify the sizes of the of the structuring element matrices (variables 'se' and 'element' in above code).'dst' is a Mat type variable used to hold the result of the dilate operation and 'closed' is a Mat type variable to hold the result of the closing operator. You can try playing with the size and shape parameters of the structuring elements as well as different number of iterations of dilation and closing to determine what works best for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.