Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Follow image contour using marching square in Python

I am new to Python and would be grateful if anyone can point me the right direction or better still some examples.

I am trying to write a program to convert image (jpeg or any image file) into gcode or x/y coordinate. Instead of scanning x and y direction, I need to follow the contour of objects in the image. For example, a doughnut with outer circle and inner circle, or a face with face outline and inner contour of organs.

I know there is something called marching square, but not sure how to do it in python?

Thank you.

like image 376
user1721648 Avatar asked Mar 01 '26 22:03

user1721648


2 Answers

You can also have a look at OpenCV's findContours function which perform the same operation very fast. It is not pure python but there is a very nice Python binding making use of numpy arrays, etc ... (the new "cv2" module).

like image 108
Nicolas Barbey Avatar answered Mar 04 '26 10:03

Nicolas Barbey


You can find an implementation of marching squares in scikit-image: https://scikit-image.org/docs/dev/auto_examples/edges/plot_contours.html

like image 45
Stefan van der Walt Avatar answered Mar 04 '26 12:03

Stefan van der Walt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!