 today's class. So, we are in module 3 and this is the fourth lecture and till now we have been learning about image classification. And we have learnt that it consists of 2 steps. Number 1 is recognizing or identifying real world objects and again by real world objects I mean the features like vegetation, water body, built up area and so on. And the second step is labeling of pixels to be classified. And till now we have understood about supervised classification and we also saw 3 classification techniques that belong to supervised classification. So, in today's lecture let us understand about the second category of labeling pixels that is unsupervised classification. Before we discuss about unsupervised classification just for a change let us view how it is carried out using SNAP that is Sentinel Application Platform. Now, SNAP is a common architecture for all the Sentinel toolboxes and you shall be getting acquainted with SNAP throughout the course of tutorials. So, let us see how unsupervised classification is performed here. So, whatever you see here the image towards your right side is a false color composite that has been created using synthetic aperture radar image. I directly point at unsupervised classification and I can see that 2 methods are specified EM cluster analysis and K means classification. I am specifying the number of clusters and the iterations and I click on run. Now, at the click of a button unsupervised classification is performed here. Now, just compare this with supervised classification as in what can be the difference? Training data right because for unsupervised classification there is no training data that has been collected which means training data is not required for unsupervised classification. It requires little or no user interaction and it is an automated classification which is used when we have insufficient observational evidence about the nature of land cover types. Let me re-itrate unsupervised classification techniques or algorithms require very little or no user interaction and it is an automated process which is used when we do not have much evidence about the nature of land cover types. Now, there are many classification algorithms that fall into the category of unsupervised classification. For better understanding we shall be picking one algorithm which is most commonly used for unsupervised clustering or unsupervised classification which is known as K means algorithm. So, before we move forward let us see how the output looks like, output of unsupervised classification and you will be performing the series of exercises as part of your tutorials. You can see class indices is projected like a map wherein each feature or land cover type is designed a particular color and this image belongs to the region of Mumbai, Maharashtra. And you can play around and change the colors that have been designed to each feature. That option is made available in Snap Toolbox. Say I want the colors to represent more contrast. I can change the colors and remember I have just labeled the classes like class 1, class 2, class 3 and so on and I have randomly indicated that this image might contain 5 clusters. I do not know how many clusters it exactly contains but then I have just randomly put a number 5 to show you how unsupervised classification is performed and you can see the final classified map in front of you wherein each pixel is designed a numerical label and the color is designed to each pixel so that all the pixels of class water body will be represented by one single color and all the pixels of say some other categories say urban, built up area will be represented by another color and so on. Remember there is no training data collection required for unsupervised classification. Now what we will do is let us learn a little bit in detail about what exactly K-means clustering does. So K-means clustering is known as one of the most commonly used non-parametric unsupervised clustering algorithms and it is known for its efficiency in clustering large data sets and it typically consists of 2 steps, very easy to follow. First of all you have to locate the initial cluster centers. So I will be making a informed guess about the initial cluster centers and then just like what you did for minimum distance to means classification the distance of each pixel from all the existing clusters is computed and it is assigned to the cluster yielding the minimum distance. Then what happens? You have to recalculate the cluster centers because now few more pixels have been assigned to the centers they are bound to change when you take the mean it will give you a different value. So it requires minimization of something known as an objective function within the cluster sum of squares. So once again K-means clustering the first step is we locate the initial cluster centers randomly you can pick the pixels and assume that it signifies cluster center or you can follow a well planned approach to pick up pixels at say definite sampling okay and after that once you assume that the cluster centers are located then you calculate the distance of each and every pixel from these existing cluster centers and once you allocate all the pixels to these cluster centers you recalculate the mean the cluster centers the cluster means because now it is going to change. So this what it is done is nothing but minimization of the objective function okay here C refers to the class N refers to the total number of samples B and D refers to the band okay. So you are doing minimization of an objective function. Now remember in general all the pixels are going to be classified based on their distance from the cluster means and once this is done the new mean vectors for each cluster is recalculated, recomputed and this process is going to be iteratively carried out until there is no variation in the location of cluster mean vectors between successive iterations. So let me try to summarize the explanation in the form of a flow chart. Say if you are given the task of writing a program in Python to perform k means clustering first step is you locate the initial clusters then you compute the distance matrix which means the distance of each and every pixel from these cluster centers you assign these pixels to the closest cluster you calculate the objective function you check whether the termination conditions are satisfied. If yes you proceed ahead if no you go back again compute distance matrix and then you recalculate everything until the termination conditions are satisfied. If yes if the conditions are satisfied you move ahead you can merge obtained clusters based on a suitable criteria because you know as I mentioned earlier you are making an informed guess to the number of classes the image shall contain. So in the example that you saw I have randomly put a number 5 it may be possible that I can even enter a number of 10 which will result in a classified map wherein there is a requirement to merge two or more clusters because they are spectrally similar I am using the word spectrally similar. So you can merge the obtained clusters based on suitable criteria and then finally obtain the clustered map. Now again I am going to re-itrate because in k-means algorithm we assume that we know how many number of clusters exist and remember there are many algorithms that belong to the unsupervised classification category and we are just briefly discussing about one algorithm one such algorithm that is k-means algorithm. For example you may have algorithms like ISO data ISO data stands for iterative self-organized data analysis techniques ISO data. So in ISO data clustering typically a split and merge routine is followed split and merge routine wherein any cluster which is having one or more large standard deviations is split in half along a line perpendicular to the feature axis and any two clusters which are very very close together are amalgamated join together split and merge nevertheless. So now we know how to create a classified map from satellite images using both supervised as well as unsupervised techniques and we have been learning about these in detail as part of today's lecture as well as previous lectures is not it. Now let me ask you a question you know you know how to create a classified map but then how can you tell with surety that the map that you generated is accurate? Let me rephrase the question that is how do you quantitatively assess the classified map? Well that is our topic of discussion now that is accuracy assessment. Now if the classification method you employ is going to incorrectly design labels they are bound to result in errors isn't it? The classification method you employed say it is going to incorrectly design labels for one it is going to assign two or three they are bound to result in errors and the common way of expressing the accuracy of classification is by preparing something known as a classification error matrix also known as a contingency table. Now you can take the example of say you appearing for an exam writing an exam and how do you know whether the answers you have marked correct or not. You know when the professor checks your answer sheets they will be already aware of the correct answers which means there is a reference set of correct answers against which your answer sheets are being compared to every time isn't it? Each time for correcting each answer sheet this reference set of answers are used isn't it? So similarly for classification accuracy assessment for accuracy assessment in image classification the idea is to have a reference data. We call it as ground truth data reference data and the result of an automated classification is always compared with a reference data ground truth data and this comparison can be carried out on a category by category basis. So whatever I have verbally mentioned is written in the slide so at any point of time feel free to pause and go through. So confusion metrics or contingency table or classification error metrics these are referring to the same table that summarizes the accuracy of classification. Now typically the error metrics are going to be square with the number of rows and number of columns equal to the number of categories whose classification accuracy is being assessed okay which means if your classified map has five classes as you saw in the earlier example the size of the error metrics is going to be five cross five five rows and five columns and so on okay. So confusion metrics once again they are square with the number of rows and columns equal to the number of categories whose classification accuracy is being assessed. Now the most commonly used for determining classification accuracy as I mentioned it is through error metrics or confusion metrics. Now you know its size k is the number of classes then the size of this metrics is going to be k cross k. Now there are different measures that can be extracted from the error metrics like users accuracy okay. We also call it as error of commission users accuracy. Here assume i and j belong to classes okay and e signifies the number of pixels okay which means e i i when I write an expression like this it means number of pixels that belong to class i which has been correctly classified to class i e i i okay and if I have written e j i it means the number of pixels that belong to class j that has been incorrectly classified to i okay. So we were discussing about different metrics that can be extracted from the error metrics starting with users accuracy or error of commission. We can have producers accuracy as well that is error of omission and the overall accuracy that is the proportion of pixels which has been correctly classified. So again instead of listening to me speak let us try to understand this concept through a very simple numerical alright. So shown here towards your left side is a map of training data after automated classification let it be any classification that has been performed and which has resulted in the map that you see towards your left side. Say u refers to urban area say w refers to water body and assume I am giving you a small subsection of the image where each pixel is signified by the letters u and w where they show two classes u for urban area and w for water body. Now towards your right side is the reference map okay remember this is not the whole image this is just the training data. So towards your right side you have the reference map of training data which has been created either by ground survey or by using high resolution satellite imagery okay. Are both the images same just have a look for one instance it is like one of those puzzles isn't it find out the missing piece. So are both the images same no you can find that there are some differences especially in the first row first column where the output of automated classification says the pixel belongs to urban area category whereas the output of reference map says no it belongs to water similarly we have third row third column the output of automated classification has classified that pixel to belong to urban area whereas the reference map says no it belongs to water okay. So there is some mismatch between the classification map that is obtained after automated classification method and the classification map which has been created by ground survey or by using high resolution satellite imagery that is the reference map and remember for creating an error matrix you need to compare the reference map with the map from the automated classification procedure isn't it alright. So now let us try to count the number of pixels that belong to the urban category and the water body category okay. I can see that 14 pixels and 11 pixels of the output from automated classification they belong to urban area and water body whereas if I look at reference map the numbers are 12 and 13 for urban area and water body okay. So now once we have finished with the counting let us try to create an error matrix or confusion matrix from this example okay. So for your easy comparison I have given both the matrices side by side now my aim is to write down the values of error matrix confusion matrix okay. We have already done the counting which means the error matrix is going to look like this okay. At the top we have reference towards the side we have output from a classification algorithm. E11 refers to the value of 12 okay where the reference says there are 12 number of pixels that belongs to urban area and the algorithm also says yes there are 12 number of pixels belonging to the urban area which means 12 has been correctly identified both by the reference as well as by the classification algorithm. When it comes to 2 references these two pixels belong to water body. Now the classification algorithm says no it belongs to urban area. So there is a mismatch okay. So there is agreement along the diagonals for example 11 is the number of correctly identified pixels as water body by both the reference as well as classification data. So now that we know how to form the error matrix we need to estimate how to calculate the producer's accuracy, the user's accuracy and the overall accuracy okay. So in this case we can first estimate the sum that is column total and row total okay and now we can calculate the producer's accuracy. When you look at the table you can see that the producer's accuracy for the urban area is nothing but 12 by 12 100 percent okay correctly classified pixels and the user's accuracy is going to be 12 by 14 okay which means 85.7 percentage for urban area. Similarly the user's accuracy for water body it is going to be 11 by 100 percentage and the overall accuracy is going to be sum of diagonals that is 12 plus 11 by total number of pixels that is plus plus plus plus 25 okay. So let me write that down user's accuracy, producer's accuracy and the overall accuracy of classification. Remember the diagonals in an error matrix signify the number of correctly identified pixels that has been correctly identified by both the reference as well as the output of classification method alright moving forward. See now we know how to create a confusion matrix or an error matrix. So now let me introduce you to one more measure to quantitatively assess the classification accuracy. This is known as the kappa coefficient kappa coefficient. Now this coefficient it summarizes the information content within an error matrix wherein the value of 0 indicates no agreement. The value of 1 indicates perfect agreement and the values of kappa you know they are often cited with classification performances you know whenever we need to compare the output from different classifier algorithms the values of kappa are often cited when classification performances are compared. Say you are using multiple classifiers right now you know about four classification algorithms three belonging to the supervised section and one belonging to the unsupervised classification category. So say you are using multiple classifiers or multiple classification algorithms to classify the same image and you want to estimate which classification method is showing superior results superior performance. Remember the comparison is for classification performance that is carried out by different methods on the same image much similar to many students in a class attempting the same question paper same satellite image subjected to different classification algorithms resulting in different classified maps and then you wish to estimate which algorithm performs best all right. Now just to make things clear let me show you another example of tabulations in an error matrix or confusion matrix this time it is for six classes water sand forest urban area paddy sugarcane. Six classes which means the size of the error matrix is going to be 6 by 6 I have represented training dataset of known cover types and then classification data. So every time I tabulate the error matrix I try to estimate the producer's accuracy as well as the user's accuracy and of course the overall accuracy all right. Now a little bit about the error matrix you know the accuracies that is producers users they are computed for carefully selected training data they are not computed for the whole image you know training dataset they are used to compute these accuracies and of course good results are going to indicate spectrally separable classes remember I am using the word spectrally separable and after training data collection one half pixels for all classes can be used for classification and the other half can be used for accuracy assessment okay whenever training data is collected you can divide it into two or more parts one part can be used for classification and the other part can be used for accuracy assessment. Now comparing every pixel in an image with a reference source will require assembling reference land cover information for an entire area and this certainly can be very expensive okay and this defeats the whole purpose of performing a remote sensing based classification in the first place. So among the training pixels as I mentioned one portion you can select it keep it aside to check the post classification accuracy such that we can have both a training set of pixels and a test set of pixels okay. Now what we will do is whatever I have mentioned is written in the slide so as before at any point of time feel free to pause and have a look alright. So with this background let me try to show you results of a case study now okay. So as we discussed in one of the earlier lectures this research work was conducted for the study site located in parts of Guntur and Krishna districts of Andhra Pradesh. So what you see in front of you are three sets of satellite images the image that you see in black and white they belong to synthetic aperture radar okay synthetic aperture radar imagery after preprocessing. So by now I hope you understand the meaning of preprocessing. So SAR imagery after preprocessing is showing A is showing HH polarized band and B is showing HP polarized band and what you see towards your right side the colorful image is nothing but the image from list four optical imagery. Here you can see that I have also drawn small boxes to signify the land use land cover type same area okay same area I am showing you that there is paddy existing in the satellite image there is water there is fallow land wasteland cotton and sand okay five classes which means the error matrix is going to have a size of 5 cross 5 okay. So to classify what we have done is we have created a false color composite using synthetic aperture radar imagery wherein HH band is assigned to red, HV band is assigned to green and I have used the ratio of two bands HH by HV assigned to blue RGB okay I have created an FCC false color composite and now when you compare the image towards the left and right you can see that there is some spectral separability between the classes I am using the word spectral separability you know visually your eye and brain tell you that there are multiple features that are signified by the difference in color that you see isn't it okay. Now we have subjected this image to both supervised as well as unsupervised classification and the image that you see is the output of unsupervised classification okay the FCC created from synthetic aperture radar images subjected to a unsupervised classification. I won't go into details about the algorithm here my intention is to show you how a typical classified map looks like from synthetic aperture radar images and how do you assess the classification performance okay. So you can see different colors show different classes and instead of directly summarizing the quantitative performance of classified through an error metrics I have already computed the accuracies that is producers accuracy users accuracy and the overall accuracy and I am tabulating the same here for the five different classes okay fallow land, cotton, sand, paddy, water okay producers accuracy and users accuracy okay. So let me hope that you could understand what was discussed as part of today's lecture because we began the class by trying to understand what is unsupervised classification and then we went on to discuss about one algorithm that is k means clustering approach and finally we understood how to quantitatively compare the performance of different classifiers through an error metrics okay. What are the metrics that you can extract from a confusion metrics or error metrics that is producers accuracy, users accuracy, kappa coefficient and the overall accuracy and finally we discussed the results of a case study that was conducted by classifying a false color composite of synthetic aperture radar image. So let me hope that you could understand these concepts and I will meet you in the next class. Thank you.