Assignment#3 AI
Assignment#3 AI
Q1. Assignment is more related to Unsupervised learning; in this learning we had studies KMEAN, FCM
algorithm, you work is to write the algorithm of KMEAN for application, application can be implementation
in any field like medical imaging, security purpose etc. After writing algorithm you must write the program
in which we should be able to check all steps of KMEAN.
Ans: Image segmentation is an important technique for image processing which aims at
partitioning the image into different homogeneous regions or clusters. Segmentation of the MRI
images is very important and crucial for the exact diagnosis by computer aided clinical tools. A
large variety of algorithms for segmentation of MRI images had been developed. However most
of these have some limitations, to overcome these limitations; modified k means clustering is
proposed. The comparison of existing segmentation approaches such as C-Means Clustering, K-
Means Clustering with Modified K-Means Clustering is performed then the performance
evaluated.
K-means is one of the simplest unsupervised learning algorithms that solve the well
known clustering problem. The procedure follows a simple and easy way to classify a given
data set through a certain number of clusters.
K-means clustering can be used in almost every domain, ranging from banking to
recommendation engines, cyber security, document clustering to image segmentation. It is
typically applied to data that has a smaller number of dimensions, is numeric, and is
continuous.
K-Means Clustering can also be used for performing image segmentation by trying to group
similar pixels in the image together and creating clusters. The different clusters formed are
different objects in an image.
K-means is an iterative algorithm in which it minimizes the sum of
distances from each object to its cluster centroid, over all clusters.
Let us consider an image with resolution of x×y and the image has to be cluster into k number of
cluster. Let p(x, y)
be an input pixels to be cluster and ck be the cluster centers. The algorithm for k-means13
clustering is following as:
1. Initialize number of cluster k and centre.
2. For each pixel of an image, calculate the Euclidean distance d, between the center and each
pixel of an image
using the relation given below.
import numpy as np
import cv2
X = np.random.randint(10,45,(25,2))
Y = np.random.randint(55,70,(25,2))
Z = np.vstack((X,Y))
# convert to np.float32
Z = np.float32(Z)
ret,label,center = cv2.kmeans(Z,2,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
A = Z[label.ravel()==0]
B = Z[label.ravel()==1]
plt.scatter(A[:,0],A[:,1])
plt.scatter(B[:,0],B[:,1],c = 'r')
plt.show()
-
Q2. In question 1 you have implemented KMEAN, where you had seen the hard clustering, you task is to
compare the hard clustering KMEAN versus Fuzzy C Mean (FCM).
FCM is most usually used techniques for image segmentation of medical image
applications because of its fuzzy nature, where one pixel can belong to multiple clusters and
which lead to better performance than crisp methods. Conventional FCM fail to perform well
enough in the presence of noise and intensity inhomogeneity in MRI images.
FCM finds its applications in variety of problems varying from data analysis to segmentation of
images. In FCM, it is possible for a data sample to belong to multiple clusters at the same time.
The similarity is indicated by the membership value. In FCM a data sample is assigned with a
membership value based on its similarity with the cluster center. The membership values are
between 0 to 1 and more the similarity, higher the membership value. FCM is a repetitive
algorithm and the solution is achieved by repetitively updating the cluster center and
membership value. These updating equations are obtained by solving the cost function. Let X =
{x1, x2, x3, . . . , xN } denotes the data with N data samples. It has to be partitioned into c-
clusters by minimizing the subsequent cost function.
The two algorithms used two different approaches, in k-means, data will be included in
one particular cluster, whereas in FCM, a data can be included in all existing clusters, but with
varying degrees of membership, in a range of values [0 1](1,2). In concept, the two algorithms
have similarities in how they work.
Fuzzy c-means clustering has can be considered a better algorithm compared to the k-
Means algorithm. Unlike the k-Means algorithm where the data points exclusively belong to
one cluster, in the case of the fuzzy c-means algorithm, the data point can belong to more
than one cluster with a likelihood.