I want to know how to find the shape of an object in the image and store it in a variable for further use. For instance,
And I want to extract only the shape, something like this(I manipulated the image in photoshop),
I just need the outline of the image, and I want to save it on the disk.I haven’t tried so far, and I’m using python 2.7
Any suggestion are welcome.
Thanks in advance!
3
Answers
There are bunch of Tutorials and question may be useful for You i think
http://www.pyimagesearch.com/2014/04/07/building-pokedex-python-indexing-sprites-using-shape-descriptors-step-3-6/
link1,link2,link3,link4,link 5
As you haven’t tried anything yet, I suggest you to try first 🙂
Here are some pointers:
Some useful information here: http://scipy-lectures.github.io/advanced/image_processing/
I don’t recommend grayscale for your image. You appear to be interested in red flower versus green background. A simple and clear way to make that distinction in your image to identify with the flower any pixels whose red value is higher than its green value.
img2
clearly shows the shape of the flower. To get the edges only, you can use a canny edge detector:The resulting file,
edges.png
, looks like:The next step, if you want, is to extract coordinates of the edges. This can be done with:
Documentation on
cv2.canny
andcv2.findContours
can be found here and here, respectively.More: What happens if you use grayscale:
The resulting image is:
The grayscale approach shows a lot of the internal structure of the flower. Whether that is good or bad depends on your objectives.