**Appendix B**

Program code for unsupervised SOM model is given below:

*Step#1 Opening Python*

Python was opened, and conda environment was selected.

*Step#2 Installing and Import Necessary Data Sources*

```
from minisom import MiniSom
import numpy as np
import matplotlib.pyplot as plt
```
*Step#3 Importing Image*

img = plt.imread('HouseTest2.jpg')

Image path is to be given here.

*Step#4 SOM Model*

#### **# Reshaping the pixels matrix**

pixels = np.reshape(img, (img.shape[0]\*img.shape[1], 3)) / 255.

**# SOM initialization** som = MiniSom(2, 3, 3, sigma=1., learning\_rate=0.2, neighborhood\_function='bubble')

**# Setting Weights** som.random\_weights\_init(pixels) starting\_weights = som.get\_weights().copy() som.train\_random(pixels, 100, verbose=True)

#### 100 is the number of training iteration

**# Quantization** qnt = som.quantization(pixels)

**# Compilation** clustered = np.zeros(img.shape)

```
for i, q in enumerate(qnt):
 clustered[np.unravel_index(i, dims=(img.shape[0], img.shape[1]))] = q
print('done.')
```
**Author details**

**103**

PETRONAS, Perak, Malaysia

Wesam Salah Alaloul\* and Abdul Hannan Qureshi

*Data Processing Using Artificial Neural Networks DOI: http://dx.doi.org/10.5772/intechopen.91935*

provided the original work is properly cited.

\*Address all correspondence to: wesam.alaloul@utp.edu.my

Department of Civil and Environmental Engineering, Universiti Teknologi

© 2020 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium,

### *Step#5 Running and Plotting of ANN Model*

```
plt.figure(figsize=(7, 7))
plt.subplot(221)
plt.title('Original')
plt.imshow(img)
plt.subplot(222)
plt.title('Result')
plt.imshow(clustered)
plt.subplot(223)
plt.title('Initial Colors')
plt.imshow(starting_weights)
plt.subplot(224)
plt.title('Learnt Colors')
plt.imshow(som.get_weights())
```
plt.tight\_layout() plt.show()

*Data Processing Using Artificial Neural Networks DOI: http://dx.doi.org/10.5772/intechopen.91935*

*Step#3 Importing Image*

*Step#4 SOM Model*

**# SOM initialization**

**# Setting Weights**

**# Quantization**

**# Compilation**

print('done.')

**# Reshaping the pixels matrix**

som = MiniSom(2, 3, 3, sigma=1.,

som.random\_weights\_init(pixels)

qnt = som.quantization(pixels)

clustered = np.zeros(img.shape)

for i, q in enumerate(qnt):

plt.figure(figsize=(7, 7)) plt.subplot(221) plt.title('Original') plt.imshow(img) plt.subplot(222) plt.title('Result') plt.imshow(clustered)

plt.subplot(223) plt.title('Initial Colors') plt.imshow(starting\_weights)

plt.subplot(224) plt.title('Learnt Colors') plt.imshow(som.get\_weights())

plt.tight\_layout() plt.show()

**102**

starting\_weights = som.get\_weights().copy() som.train\_random(pixels, 100, verbose=True)

100 is the number of training iteration

*Step#5 Running and Plotting of ANN Model*

clustered[np.unravel\_index(i, dims=(img.shape[0], img.shape[1]))] = q

img = plt.imread('HouseTest2.jpg')

Image path is to be given here.

*Dynamic Data Assimilation - Beating the Uncertainties*

pixels = np.reshape(img, (img.shape[0]\*img.shape[1], 3)) / 255.

learning\_rate=0.2, neighborhood\_function='bubble')
