Welcome to Kaikang Zhu's web page

Assignment Title

CS 585 HW 2
Kaikang Zhu

Problem Definition

To design and implement algorithms that can analyze and recognize random shapes. Using a shape dataset (in the "shapes_train2018" folder) that consists of 501 synthesized color image with randomly sized and colored object shapes in it. The shapes are categorized into three types: square, circle and equilateral triangle. For each image, ground-truth annotations are provided in the "annotations" folder where you can find a binary mask for each shape that occurs in every image with the file name indicating the shape type.

Requirements 1.For each shape image, determine its background color and label each and every shape blobs according to their color. 2.For each shape blob, implement a border following algorithm to find its outermost contour (i.e. the border pixels) and compare it with OpenCV's "findContours" function. 3.For each shape blob, classify its border pixels (in other words, segment its outermost contour) into three types: borders against the background, borders against another shape blob and borders that are a border of the whole image. 4.(Optional) You may also segment the border according to their convexity, i.e. find out all convex segments and concave segments. This may help you analyze its shape type. 5.For each shape blob, come up with an algorithm that can recognize its shape type (square, circle, or triangle).

Method and Implementation

For the first requirement, I come up with using k-means algorithm to label every shape blob in pictures. Opencv has a built-in kmeans function. We can implement it. To label the whole dataset, we need to format the file path and set a while loop to read all the pictures and save them in a new folder.

The second requirement is implementing a border following algorithm. I first use the findContour() function. And I choose the outermost border. To show the border, I use the drawContours() function. After drawing the contours of all the images, save them in a new folder. Then I implement my own border following algorithm which finds out the border pixel according to their difference to neighbour pixel values.

For the third requirement, I put points of blobs in several vectors. Finding the contour point if their pixel value is different form their neighbour values. After that, give the boder pixel another color to show the border aganist each blobs, against border and the whole contour.


The experiment result can be shown in the result folder.

We can visualize the result and find it's correct.



Trial Source Image Result Image
label image
label image2
draw contour


Discuss your method and results:


Based on your discussion, what are your conclusions? What is your main message?

I have completed some of the requirements. And I need to do more to find and segment outermost border correctly.

Credits and Bibliography

reference:https://blog.csdn.net/hei_ya/article/details/51387624 https://www.cnblogs.com/mikewolf2002/p/3372846.html https://docs.opencv.org/2.4/modules/core/doc/clustering.html

I have discussion on the first requirement about how to label the shape blob of the image with my classmate Ziyang Chen.