File Exchange

image thumbnail


version 1.0 (3.76 KB) by

CONTOUR_FOLLOWING takes a B&W image, returns the sorted contour points.



No License

C = CONTOUR_FOLLOWING(BW) takes BW as an input. BW is a binary array containing the image of an object ('1': foreground, '0': background). It returns a circular list (N x 2, C(1,:)=C(end,:)) of the (row,column)-coordinates of the object's contour, in the order of appearance (This function was inspired from the freeman contour coding algorithm).

- if the object is less than 3 pixels, CONTOUR_FOLLOWING sends back [0 0].
- the algorithm is quite robust: the object can have holes, and can also be only one pixel thick in some parts (in this case, some coordinates pair will appear two times: they are counted "way and back").

This function was originally developed in order obtain an initialization for a snake algorithm.

The .zip files contains some example images and a test script.

Comments and Ratings (11)

Wei Teck

Image Analyst

Image Analyst (view profile)

It's not clear what this code does that the function bwboundaries(), in the Image Processing Toolbox, already does. Can you explain the differences, if any?


eunn (view profile)

nice one!~

Great job Francois,
But i have still a problem with this code. The code moves the orientation of the object to find coordinates (as we can see in your picture to introduce your code).
In my case is very important to keep the initial object in the same axis system. To be more clear i want to record with a fixed camera several binary images of an object which will be a little perturbated. So if i want to compare the perturbated object with a non-perturbated one, i need to keep the same axis system (for exemple, the entire image).
I hope have been enough clear about my problem.
Thx again for your sharing.

Raymond Cheng

Thanks for your sharing.

priyanka desai

Can this be used for Video,, If yes please let me know , thanks in advance

Andrea Morgera

Robust and easy to use.

François Mourougaya

Dear Bashir,
my intention was to get the contour of only one object. In your application you sometime have two objects. If you get at least one pixel of one of the objects you can remove it easily (look after geodesic reconstruction in mathematical morphology). Once this is done you can repeat the process for each other object.

Bashir Ayesha

Hi Francois Mourougaya,
How r u?
Your code is good but it contains a little bit problem. If the image is broken it doesnot show all the contours. Let us consider the image of bone fracture. If its broken from middle then it will show contour of only one part and the contour of the other part doesnot show. If you resolve this problem them its the best program I have ever seen

Amit Shesh

Nice program and faster than I expected. If dealing with only a BW image, you can get the edges faster than bwmorph and imerode which can be very slow for large images. Use an averaging filter and filter out its results.

Fran?ois Mourougaya

Hello everyone, I'm the author of this file, and I see there were already some downloads, but no rating or comment.

If you download it, can you please give feedback, to know if you found it usefull or if you think its total crap (in this case, please tell me what's wrong so I can improve it !).

Thanks anyway for you interest,

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today