0 0 0 15 0 36 30 40 The simplest method for contour extraction is to traverse each square, extracting parts of the contour as we go. In three dimensions, this is called Marching Cubes: in two dimensions, here is an example of Marching Triangles:
Marching Triangles for Contour Extraction
As you can see, this has several disadvantages: it spends a lot of time in empty space, it produces disconnected fragments of contours, and it doesn't have a notion of an "object". A rather better way of extracting contours is the continuation method:
The Continuation Method
Here, starting at a point known to be on the contour, we just follow it around until we return to our starting point. But this requires us to know a seed: a point on the contour to start from. More importantly, we need one seed for each contour. This is where the contour tree comes in: as a source of seeds for the continuation method. Because we know that paths in the tree correspond to paths in the data, we know that we can always walk uphill (or downhill) to a given contour, provided that we start walking uphill from the right place. In other words, what we need is a seed path that leads us to a seed for the contour. Since these paths also exist in the contour tree, it is not difficult to see that instead of one seed for each possible contour, all we need is one seed path for each edge in the contour tree. Better yet, it turns out that we can always start at a saddle and find a suitable path: a concept we refer to as the path seed. At each saddle, we associate the possible directions of ascent with the corresponding edges of the contour tree:

Contours, Contour Tree and Directions of Ascent (Path Seeds)

Path Seeds Stored in the Contour Tree
Path Seeds & Continuation: