# Image Analysis and Processing for Generating Camouflages from Digital Earth Photographs
## 4 Selected Technical Aspects of the Camouflage Generator Approach
### Logic Layer
#### 4.2.2 CammoGenerator Component  
The _CammoGenerator_ component is based on a facade design pattern that provides a simple interface for generating camouflage and managing its properties. The classes included in this component are shown in the class diagram in Figure 12. Facade is the _CammoGenerator_ class that provides parameters of the generated camouflage such as size, background color, layers, and _Generate()_ method, which is used to generate the camouflage. The facade needs a _PatternGenerator_ class that provides _GetShape()_ method to generate a spot list for a given layer, and a _Pixelizer_ class that has _Pixelize()_ method to convert a bitmap image into a square image of a given size. For the _GenerateMap()_ method to work, the _PatternGenerator_ class requires the use of the _CenectedComponentLabeling_ and _fBMPatternGenerator_ classes. The _CenectedComponentLabeling_ class is used to convert a two-dimensional list of logical type into a list of spots, while _fBMPatternGenerator_ is a class for generating the pattern itself, which is achieved using _Simplex Noise_[17] and its transformations using the implemented _fractional Brownian motion_[18]. A simplified schema of camouflage generation algorithm of _Generate()_ function is shown in Figure 13. The following parameters were given to the function: the size of created image, the background color, and the layers needed to generate the camouflage. The generation of camouflage begins with the operation of generating the shapes for each color, i.e., layer. This operation consists of two stages: generating a map and extracting the shapes. The map generation function is shown in Algorithm 1 and consists of noise generation operation _SimplexNoise_. This noise is then transformed with function (1), which transforms the shapes generated by noise into the camouflage spots:  
\[fbm(fbm(fbm(p+V_{1})+V_{2})+V_{3}) \tag{1}\]  
where:  
\(p\)--pair \((x;y)\), specifying the coordinates on the two-dimensional array of the camouflage pattern;  
\(v_{1}\); \(v_{2}\); \(v_{3}\)--appropriately selected vectors, transforming the noise into a camouflage pattern;  
\(fbm()\)--_fractional Brownian motion_ function [18]. Figure 12: Class diagram for _CammoGenerator_ component in logic layer of _CammoGenerator_ application. Figure 13: Simplified schema of camouflage generation algorithm. ```
1 FunctionCammoGeneratorComponentFCamouflageMapGeneration(\(shape_{i}\)): GenerateSimplexNoise with Given Grain(); if\(fbm(fbm(fbm(p+V_{1})+V_{2})+V_{3})\%256<60\)then
4 SetValue In [p] array = true; else
5 SetValue In [p] array = false;
```  
**Algorithm 1**CammoGenerator component--camouflage map generation function. The _fbm()_ function adds successive less amplitude noise to the base noise while keeping it dependent on the base noise, resulting in increased detail for the base noise. It allows to obtain more varied noise values. This effect is shown in Figure 14. After transforming the noise using function (1), a _modulo 256_ operation is performed on the noise values. Depending on whether the value is greater or less than a predetermined threshold, the pattern table for the layer is set to _true_ or _false_ at the \(p\) position. When the entire pattern table is filled with values, the shapes are created from the _true_ values using the algorithm shown in Algorithm 2. This algorithm groups points into shapes by iterating over all _true_ values in the pattern table. For a given point in the table, labels of neighbor points are checked. In the case where the neighbors do not have assigned labels, the current value of the label is assigned to the point and the value of the label is increased by one. When a point has at least one neighbor with a label, the smallest neighbor label is assigned to the point and its neighbors' labels, so the joining of labels takes place. An example of the algorithm's operation is presented in Figure 15, where the tested point is marked in red and the neighbors in blue.