## Problem 1

## Problem Definition

- Implement a connected component labeling algorithm and apply it to the data below. Show your results by displaying the detected components/objects with different colors. The recursive connected component labeling algorithm sometimes does not work properly if the image regions are large. See below for an alternate variant of this algorithm. If you have trouble implementing connected component labeling, you may use an OpenCV library function, but you will be assessed a small 5 point penalty.
- If your output contains a large number of components, apply a technique to reduce the number of components, e.g., filtering by component size, or erosion.
- Implement the boundary following algorithm and apply it for the relevant regions/objects.
- For each relevant region/object, compute the area, orientation, and circularity (Emin/Emax). Also, identify and count the boundary pixels of each region, and compute compactness, the ratio of the area to the perimeter.
- Implement a skeleton finding algorithm. Apply it to the relevant regions/objects.

## Method and Implementation

- Connedt component labeling
- Flood filling algorithm
- Opening
- Draw boundary
- Boundary following algorithm
- Object area, orientation, circularity
- Skeleton

Start from the top-left pixel of the figure, scanning through the whole figure until meet the first non-zero pixel. Then recursively find all neighbours and neighbours' neighbour until we have labeled the whole region. Then scan for next unlabelled non-zero pixel.

To get rid of all noise in the figure, we use opening to keep only large components in the figure. First we do erosion then dilation so small components would be removed and large ones would be keeped.

Start from the top-left pixel of the figure, scanning through the whole figure until we fing the first non-zero pixel. Then search its 8-neighbour pixels clockwise to find the next boundary point.

For area, orientatio, circularity, compactness computing. We use opencv funtions to get moments and use formula to compute the result.

We keep eroding the image when situation fit our rules until the figure's skeleton is found.

## Experiments

When finding components of the figure, we try flood filling and sequential labelling. We find there is little different in time costing between this two and huge space costing so we choose last one.

And when drawing boundary, firstly is hard to implement boundary following to different region in the figure. So then we use labelling when we do boundary following to fix the problem.

## Results

open-bw-full

open_fist

open-bw-partial

tumor-fold

## Discussion and Conclusion

Discuss your method and results:

We implement our labeling algorithm pretty well on our figure. and also find the boundary and skeleton of each region. Lastly, we calculate area, circularity and compactness of our object. When we first implement our algorithm on multiple object figures, we do meet some problems since at first we can't detect multiple regions. Finally we do labelling when we implement algorithms and successfully detect all.