*Readme

COMPUTER VISION
HOMEWORK 2

Name: Yuandi Jin
UNI: yj2246

I have worked out all of the assignments on my Ubuntu Linux.
The test on CUNIX is also successful.
My code is in C++.

Here are some key points of the programs I have written.

/*=====Makefile=====*/
I set the threshold to 120, which I think is the best.
With 120, we can see the objects clearly and we don't loss too much information in thin lines.

I added ./ in front of the command lines. If I don't add them, the "make" fails on Ubuntu and Cunix.
	./p1 two_objects.pgm $(THRESHOLD) p11.pgm
	./p1 many_objects_1.pgm $(THRESHOLD) p12.pgm
	./p1 many_objects_2.pgm $(THRESHOLD) p13.pgm
	...

/*=====p1.cpp=====*/
It is clear by itself...

/*=====p2.cpp=====*/
I used Union-Find Set (UFS) to build the equivalence table.
My operations are:
1. First-pass labeling using the algorithm taught in the class. The objects are labeled but with too many labels that should be "equivalent". I union the equivalent labels in corresponding UFS.
2. Second-pass labeling dealing with the equivalent labels. For each label, find the UFS that it lies in (that is, find its root). Then use the min label in the UFS to replace it. After this, the objects are labeled by non-consecutive numbers.
3. Use consecutive natural numbers to replace the non-consecutive ones.
To demoonstrate how to use it, we assume that the equivalence table is like:
1==1,2,4,6
2==1,2,4,6 (not used)
3==3,5
4==1,2,4,6 (not used)
5==3,5 (not used)
6==1,2,4,6 (not used)

Important data structure:
vector<int> *eqTable
	equivalence table, for example, eqTable[1] has elements that are equivalent to label 1: 1,2,4,6, eqTable[3] has 3,5. Notice that eqTable[0] has one element 0.
vector<int> tempLabel
	to store the used labels after operation 2, for example, it has 1 and 3.
int **labelArray
	label in operation 1.
int pre[MAXSIZE+1]
	the linked list used in the UFS.
		At the beginning, assign -1 to all the nodes in the linked list, 
		so that later for root node x, pre[x] = -num (num is the number of nodes in the corresponding UFS); 
		for non-root node y, pre[y] > 0, pre[y] is the father of y.

/*=====p3.cpp=====*/
Draw a star at the centroid. (xbar,ybar)
Draw a line of length 100 to indicate the orientation.
NOTICE: I DEFINE THE ANGLE IS THE ANGLE BETWEEN THE AXIS OF MINIMUM INERTIA AND !!!HORIZONTAL AXIS!!!
I THINK THIS DEFINITION MATCHES OUR NOTES.

/*=====p4.cpp=====*/
I used these rules for recognization:
(objList[i].area > 0.8*standardObjList[j].area)
&&(objList[i].area < 1.25*standardObjList[j].area)
&&(objList[i].minMomentInertia > 0.8*standardObjList[j].minMomentInertia)
&&(objList[i].minMomentInertia < 1.25*standardObjList[j].minMomentInertia)
&&(objList[i].roundness > 0.8*standardObjList[j].roundness)
&&(objList[i].roundness < 1.25*standardObjList[j].roundness)

I think these rules are not so good. area should not be used as one of the rules if the images are taken from different distances.
But in this homework, the distances are more or less the same, so we can apply area.

