$25
1. Calculate the global threshold value of the given images palmleaf1.pgm and palmleaf2.pgm using Otsu’s thresholding algorithm, and display the thresholded binary images. Comment on your observations.
2. In all the following questions, perform K-means clustering on the two input images (car.ppm and flower.png) for K = 3 clusters. Use only Euclidean distance as the distance measure for all iterations. Basic data units to be clustered are vectors containing pixel data, i.e., [r g b]. Perform 5 iterations of the algorithm. To visualize the output of k-means clustering, replace each pixels in the input image with the cluster center it belongs to and display the resulting image.
(a) Perform K-means clustering with initial cluster means as follows:
• cinit1 - [255 0 0]
• cinit2 - [0 0 0]
• cinit3 - [255 255 255]
(b) Perform K-means clustering on both images using random initialization of cluster means.Generate 3 random vectors of size 1×3 that are sampled from uniform distribution in [0 255] and use them as the cluster centers to begin the K-means with. Perform K-means clustering using N such initializations. The cost corresponding to the output of k-means clustering can be computed as
where dist measures the Euclidean distance between a pixel color value pi and its cluster center ck, and P refers to the total number of pixels in the image. Use N=30 (which means that you will repeat K-means clustering with 30 different random initializations), and find the cost corresponding to the output in each case. Among the 30 values that you got after repeatedly running the K-means, find the output corresponding to the lowest and highest value of C.