# contours and smoothing

My question relates to finding contours in data and then ‘smoothing’ these contours. My input will simply be a grid of 4 bit quantities (0-15).

For example, consider the following grid of data:

(zero equals no data)

0 0 0 0 0 0 0 2 2 2 0 0
0 4 4 0 0 0 0 2 0 2 0 0
0 4 4 0 0 0 0 2 0 2 0 0
0 0 0 1 1 1 0 2 0 2 0 0
0 0 0 1 0 1 0 2 2 2 0 0
0 0 0 1 1 1 0 0 0 0 0 0

In the above example, there are obviously 3 rectangles. I’m in search of an algorithm that will identify the contours/boundaries of these rectangles and then a second algorithm to ‘smooth’ out the blocky corners.

My biggest concern at this point is smoothing the contour fields. I’ve found an algorithm to identify the contours in one of the graphics gems books (Graphics Gem III). I’ve considered using this algorithm in conjunction with some sort of bezier curve algorithm to smooth the corners.

Anyway, any links, books, suggestions you can provide will be appreciated.

hi !
For problem1 :
Identification of closed boundaries(I am not sure of the algo that you have already found). But I suggest you could have a look at the snake algorithm. The approach is that it first identifies a seed and marks pixels around it , to form a chain.

For problem2:
Smoothing the corners.

• If the corners are always at 90 degree to each other, you can use 4 mask . Example a mask of the following form can be used for the top left corner
0 0 0
0 1 1
0 1 0
It will require four passes for the entire image
• Another approach is that from algo1, if you have a segmented output. That is the result is in the form of a line. You can use the averaging algorithm ( smoothing line ) . It works by creating a new segment by joining the midpoints of the input segments.

Hope the above ideas help
Regard
sOphia