## 3 Materials and Methods
### Data
The algorithm has been executed using an image-partitioning algorithm that infers the labels of the land cover classes by analysing intra-class similarity and, vice versa, the contrast between the classes. This method presents a machine learning approach for assigning pixels into the defined groups (or coherent clusters) according to their intensity and brightness, as seen in Listing 4. The clustering and classification of data is a commonly accepted practice for land cover mapping aimed at modelling changes in a forest structure by examining land-use categories [2; 54; 88; 101; 102]. ```
1#Setupworkingdirectory
2 setwd(\"Users/polinalemenskova/DocumentsfR/$3_UC_k_means/Basoko_LC08_LITP_177059_20220208_202212_22_17\")
3#Importingdata
4 Landast_Basoko2022=list.files(\"IUsers/polinalemenskova/Documents/fR/$3_UC_k_means/Basoko_LC08_LITP_177059_20220208_20220212_02_17\")
5#Printingthelist
61 list.files()
7#CreatingtheobjectofRasterLayerclassforoneband
8 Basoko2022.B2<-raster(Landsat_Basoko2022[2])
8 Basoko2022.B2
91#Generatingthecolorpaletteable
10 colors=Kovesi.linear_grey_10_95_c0(100)
11#Plottingoneband
12 plot(Basoko2022_B2,
13 main=Landsat_OLITP_187059_20220208_20220212_02_17\", font.main=2,exex.main=0.90,axes=FALSE,box=FALSE,legend=FALSE,col=colors)
15#StackingthedataforecrateRasterStack. 16 Landsat_Basoko2022_stack<-stack(Landsat_Basoko2022)
17#Turningstackintohatbrick. 18#Landsat_Basoko2022_brick<-brick(Landsat_Basoko2022_stack)
19 Landsat_Basoko2022_brick<-brick(Basoko2022_B2)
20#Viewingbrickattributes
21 landast_Basoko2022_brick
22#PlottingtheRGBtripletfromtheRasterBrick
23 plar=car(-par(n.readonly=TRUE)#back-uppar
24 par(nrowe(1,1))
25 plotRGB(Landsat_Basoko2022_brick)
26#Runningtheclassification
27 set.seed(25)
28 unC<-unsuperClass(Landsat_Basoko2022_brick,nSamples=100,nClasses=10,nStarts=5)
29 unc
30#Creatingthecolorpaletteable
31 colors=<-kovesi.diverging_rainbow_bgym_45_85_c67(10)
32#Plottingaamp
33 plot(unCsmap,main=\"K-meansClusteringforLandsat-8 OLITP_177059_20220208_20220212_02_T1\", font.main=2,exex.main=0.95,col=colors,axes=FALSE,box=FALSE,legend=FALSE)
34#Addinglegend
```
Listing 4: R code used for running the unsupervised classification by k-means clustering; here a case of Basko* [3]legend('topleft',legend=c(\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\"),fill=colors,title=\"Classes\",horiz=FALSE,by=\"n\",text.font=3,ncol=1)
```  
The image for classification was generated by stacking the data, which enabled us to create the RasterStack as a collection of RasterLayer objects. In turn, they were generated from the raster layers of the selected bands with the same spatial extent and resolution, that is, 30 m for the most of the Landsat-8 OLI/TIRS bands. Afterwards, RasterStack was merged into a RasterBrick, which is a multi-layer raster object created from the multi-layer files of RasterStack, made up of Landsat bands. The similarity between the RasterStack and RasterBrick classes consists in the fact that both are generated with a stack of the raster Landsat bands. However, the processing time for the RasterBrick is shorter in the R environment compared to the RasterStack because RasterBrick is less flexible and is merged already as a single file. The procedure and the output of the k-means clustering is presented in Figure 6, which shows the console of the RStudio with statistical information on cluster centroids and the sum of squares for each processed map, respectively. The cluster map on the right of the print screen depicts the class memberships of the pixels; in this case, we give the example of Basoko town in the year 2013, as seen in Figure 6.  
Thus, the automatic clustering analysis by R has been performed without prior knowledge of class membership of those pixels using a principle of partitioning of the raster file based on the generalization of the matrix of cells. Based on the automatic analysis of pixel brightness, the pixels of a given symbol were partitioned into the same spectral class, which belongs to one of the 10 clusters.