**2.2 Import pictures**

Dim and noisy images were imported into Netlogo using the command "importpcolors", which transformed the luminance values of pixels into the grey values of patches. This Netlogo function limits the luminance values of grey-scale images to the range between 0 (black) to 9.9 (white), whereby the total number of possible grey values is 110. Although image information is reduced by this function, the human eye is unable to recognize any difference between images having a grey value range of 110 or higher.

## **2.3 Image statistics**

For the automatic adjustment of the two parameters gain and variability threshold, a simple calculation of the global image statistics was performed and image noise was estimated. The median and variance of the grey values of all pixels were analyzed and saved as *median\_grey* and *var\_grey*, respectively. Before processing 'rgb' images, the parameter *median-grey* was calculated by averaging over the luminance values of all color channels. In contrast, *var\_grey* was calculated from the channel with the highest average luminance value. The parameter *gain* acts as a factor of ln-transformed grey values (adjusts image brightness) and was derived from *median\_grey* according to Eq. 1. *gain* cannot be smaller than 1.

$$\text{gain} = \mathbb{S} - median\\_grey\tag{1}$$

**39**

*From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising*

*N*=1 *X*

exhibiting various noise levels and brightness values.

**2.6 Image processing step 1: logarithmic transformation**

transformation was stored as *greyLn* at the focal pixel.

**2.7 Image processing step 2: adaptive spatial averaging**

10 pixels and the minimum size to 1 pixel.

*XNE* ∣ *mean*\_*grey*\_*local* < *var*\_*grey*/ (*median*\_*grey* − 1) (2)

The noise estimation of color images was restricted to the color channel with the

 *threshold*\_*var* = 0.0002 ∗ [(*noise*\_*estimate* + *var*\_*grey*) ∗ *median*\_*grey*] + 0.92 + ( *gain*/10) (4)

The logarithmic transformation of luminance values results in disproportionate

*greyLn* = ln (*grey*\_*value* + 1.5) ∗ *gain* (5)

Image noise was widely removed by means of 'adaptive spatial averaging', a procedure that is executed by each pixel and evaluates the local variability of the *greyLn* values to calculate the radius of the circle in which grey value averaging is executed (locals means computation). Adaptive spatial averaging was executed in parallel at the level of pixels. Each pixel expands a circle in steps of one patch as long as the variability of the average *greyLn* values of the pixels of each color channel within this circle remained below *threshold\_var*. Once the dimension of this circle was found, the *greyLn* values were averaged and saved as *grey\_avg* value for the focal pixel. This averaging of *greyLn* values in the circle was calculated for each color channel separately. The maximum radius of the expanding circle was restricted to

amplification of the small grey values. The image contrast of very dim images was improved by calculating the natural logarithm of the luminance values of patches of each color channel and multiplication of the result by the *gain* factor using Eq. (5). Adding the constant 1.5 to the luminance values prevents them from becoming smaller than zero after ln-transformation. The result of this logarithmic

If *noise\_estimate* was smaller than 0.01, *threshold\_var* was always set to 0.01, which is low enough to preserve fine image details, but high enough to remove the

This NV algorithm derives all its parameters from global image statistics (*median\_grey* and *var\_grey*) and the *noise\_estimate*. Eq. (4) defines the threshold that was used for the adaptive spatial averaging procedure. It was found empirically by testing numerous terms that allow to predict the parameters that result in high quality output images with respect to the conservation of image details and the (Peak signal-to-noise ratio) PSNR value. Eq. (4) was derived from manuallyadjusted parameter combinations that were obtained from 10 different images

*abs*(*mean*\_*grey*\_*local* − *luminance*)/*X* (3)

*DOI: http://dx.doi.org/10.5772/intechopen.91911*

*noise*\_*estimate* = ∑

highest average luminance value.

**2.5 Parameter estimation**

remaining noise.

## **2.4 Noise estimation**

A rather simple estimation of noise can be obtained by summing up the differences between the grey values of each pixel and the average grey values of surrounding pixels in rather homogeneous regions of the image. For this purpose, the local average luminance value (*mean\_grey\_local*) and local variance of luminance values (*var\_grey*) of surrounding patches were calculated in a circle with a radius of 4 pixels. Since brighter images tend to show a higher variability of grey values, the noise estimation was restricted to those pixels XNE having circles in which *mean\_ grey\_local* was smaller than the ratio between *var\_grey* and (*median\_grey* – 1) (see Eq. (2)). Noise estimation was computed according to Eq. (3), whereby X denotes the number of patches in the homogeneous image regions.

*From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising DOI: http://dx.doi.org/10.5772/intechopen.91911*

$$X\_{NE} \mid mean\\_grey\\_local < var\\_grey / (median\\_grey - 1)\tag{2}$$

$$\text{noise\\_estimate} = \sum\_{N=1}^{X} \text{abs}\{mean\\_grey\\_local\ - humanance\} / X \tag{3}$$

The noise estimation of color images was restricted to the color channel with the highest average luminance value.

#### **2.5 Parameter estimation**

*Biomimetics*

**2.2 Import pictures**

**2.3 Image statistics**

**2.4 Noise estimation**

is performed in the second image processing step of this night vision method and preserves object contours and image sharpness. This procedure assumes a higher variability of luminance values near object contours as compared to homogeneous image regions. Thus, circles in which local luminance values can be averaged may not exceed a critical variability of grey values (*threshold\_var*). Adaptive averaging is performed at the level of pixels and evaluates the variability of local grey values to find the dimension of a circle in which the variability of grey values remains below the predefined variability threshold. After exceeding this threshold, the average of grey values of pixels belonging to this circle is calculated and stored at the central pixel. As a final processing step an automatic contrast-enhancement procedure was applied by means of linear histogram stretching. Two parameters (gain and variability threshold) are essential for this method and were derived from global image statistics and a simple kind of noise estimate. The image-enhancement algorithm described here was developed using Netlogo 5.2 (developed by Uri Wilensky; http://ccl.northwestern.edu/ netlogo/), a multi-agent programming environment that allows the parallel execution

of commands at the level of pixels (named patches in the Netlogo language).

Dim and noisy images were imported into Netlogo using the command "importpcolors", which transformed the luminance values of pixels into the grey values of patches. This Netlogo function limits the luminance values of grey-scale images to the range between 0 (black) to 9.9 (white), whereby the total number of possible grey values is 110. Although image information is reduced by this function, the human eye is unable to recognize any difference between images having a grey value range of 110 or higher.

For the automatic adjustment of the two parameters gain and variability threshold, a simple calculation of the global image statistics was performed and image noise was estimated. The median and variance of the grey values of all pixels were analyzed and saved as *median\_grey* and *var\_grey*, respectively. Before processing 'rgb' images, the parameter *median-grey* was calculated by averaging over the luminance values of all color channels. In contrast, *var\_grey* was calculated from the channel with the highest average luminance value. The parameter *gain* acts as a factor of ln-transformed grey values (adjusts image brightness) and was derived

*gain* = 5 − *median*\_*grey* (1)

A rather simple estimation of noise can be obtained by summing up the differences between the grey values of each pixel and the average grey values of surrounding pixels in rather homogeneous regions of the image. For this purpose, the local average luminance value (*mean\_grey\_local*) and local variance of luminance values (*var\_grey*) of surrounding patches were calculated in a circle with a radius of 4 pixels. Since brighter images tend to show a higher variability of grey values, the noise estimation was restricted to those pixels XNE having circles in which *mean\_ grey\_local* was smaller than the ratio between *var\_grey* and (*median\_grey* – 1) (see Eq. (2)). Noise estimation was computed according to Eq. (3), whereby X denotes

from *median\_grey* according to Eq. 1. *gain* cannot be smaller than 1.

the number of patches in the homogeneous image regions.

**38**

This NV algorithm derives all its parameters from global image statistics (*median\_grey* and *var\_grey*) and the *noise\_estimate*. Eq. (4) defines the threshold that was used for the adaptive spatial averaging procedure. It was found empirically by testing numerous terms that allow to predict the parameters that result in high quality output images with respect to the conservation of image details and the (Peak signal-to-noise ratio) PSNR value. Eq. (4) was derived from manuallyadjusted parameter combinations that were obtained from 10 different images exhibiting various noise levels and brightness values.

$$\begin{array}{c} \text{threshold\\_var = 0.0002 \* [(noise\\_estimate + var\\_grey) \* median\\_grey]} \times 0.92 \\ \text{+ (gain/10)} \end{array} \tag{4}$$

If *noise\_estimate* was smaller than 0.01, *threshold\_var* was always set to 0.01, which is low enough to preserve fine image details, but high enough to remove the remaining noise.

#### **2.6 Image processing step 1: logarithmic transformation**

The logarithmic transformation of luminance values results in disproportionate amplification of the small grey values. The image contrast of very dim images was improved by calculating the natural logarithm of the luminance values of patches of each color channel and multiplication of the result by the *gain* factor using Eq. (5). Adding the constant 1.5 to the luminance values prevents them from becoming smaller than zero after ln-transformation. The result of this logarithmic transformation was stored as *greyLn* at the focal pixel.

$$\text{greyLn} = \ln \text{(grey\\_value + 1.5)} \ast \text{gain} \tag{5}$$

#### **2.7 Image processing step 2: adaptive spatial averaging**

Image noise was widely removed by means of 'adaptive spatial averaging', a procedure that is executed by each pixel and evaluates the local variability of the *greyLn* values to calculate the radius of the circle in which grey value averaging is executed (locals means computation). Adaptive spatial averaging was executed in parallel at the level of pixels. Each pixel expands a circle in steps of one patch as long as the variability of the average *greyLn* values of the pixels of each color channel within this circle remained below *threshold\_var*. Once the dimension of this circle was found, the *greyLn* values were averaged and saved as *grey\_avg* value for the focal pixel. This averaging of *greyLn* values in the circle was calculated for each color channel separately. The maximum radius of the expanding circle was restricted to 10 pixels and the minimum size to 1 pixel.

### **2.8 Image processing step 3: enhancement of image contrast**

After adaptive spatial averaging, image contrast can be enhanced if the grey value variability of the resulting image is low (variance <75). This was done by means of linear histogram stretching, which uses the lowest and highest *grey\_avg* values of the image to calculate the resulting grey value of each patch. This was achieved by using Eq. (6), which sets the lowest value to 0 (black) and the highest value to 9.9 (white) while intermediate values are assigned to shades of grey.

$$\begin{array}{c} \text{gry\\_value} = \{ \{ \text{gry\\_avg - min (gry\\_avg)} \} / \{ \text{max (gry\\_avg)} \} \\ \text{ -- min (gry\\_avg)} \} \* 9.9 \end{array} \tag{6}$$

#### **2.9 Evaluation of performance**

The performance of this algorithm was evaluated by calculating the peak signal-to-noise-ratio (PSNR) using the method described by Russo [20]. The result is given in dB and quantifies the difference between the noisy input image and the processed image. Higher dB values indicate better denoising performance. To evaluate PSNR between the input and the output images, images were exported from Netlogo in 'png' format and a Python script was programmed to execute the function "compare\_psnr" offered in the "skimage.measure" library.

### **3. Results image denoising**

The sequence of image-processing steps illustrated in **Figure 1** allowed the strong enhancement of the image contrast in dim images and simultaneously removed sensor noise. The performance of this simple, dynamic spatial domainfiltering algorithm depends on two parameters that can be estimated by evaluating global image statistics and executing a simple noise estimation method.

#### **Figure 2.**

*Performance of the NV algorithm using a dim image of a mobile phone camera as input. (A) The original image is black. (B) After automatic histogram equalization sensor noise was amplified. (C) The NV-processed image exhibits a high level of image contrast and contains a low amount of noise. PSNR of C: 25.9 dB. Hartbauer holds the copyright of this picture.*

**41**

**Figure 3.**

*From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising*

Application of this NV algorithm to an underexposed image that was taken in a very dim room resulted in an output image with a high level of contrast and rather low noise level (see **Figure 2C**). On the contrary, the automatic adjustment of brightness and contrast offered by commonly used image processing software

*Performance of the NV algorithm using a dim natural image as input. (A) Noisy image of a village on Mallorca (printed with permission from Buades; see Buades et al. [6]). (B) Noise was amplified after histogram stretching. (C) The output of the NV algorithm yielded a reduced amount of noise (PSNR = 35.3 dB)* 

*and shows a higher quality regarding image details and contrast.*

*DOI: http://dx.doi.org/10.5772/intechopen.91911*

*From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising DOI: http://dx.doi.org/10.5772/intechopen.91911*

#### **Figure 3.**

*Biomimetics*

**2.8 Image processing step 3: enhancement of image contrast**

*grey*\_*value* = {[*grey*\_*avg* − *min*

− *min*

**2.9 Evaluation of performance**

**3. Results image denoising**

After adaptive spatial averaging, image contrast can be enhanced if the grey value variability of the resulting image is low (variance <75). This was done by means of linear histogram stretching, which uses the lowest and highest *grey\_avg* values of the image to calculate the resulting grey value of each patch. This was achieved by using Eq. (6), which sets the lowest value to 0 (black) and the highest value to 9.9 (white) while intermediate values are assigned to shades of grey.

The performance of this algorithm was evaluated by calculating the peak signal-to-noise-ratio (PSNR) using the method described by Russo [20]. The result is given in dB and quantifies the difference between the noisy input image and the processed image. Higher dB values indicate better denoising performance. To evaluate PSNR between the input and the output images, images were exported from Netlogo in 'png' format and a Python script was programmed to execute the

The sequence of image-processing steps illustrated in **Figure 1** allowed the strong enhancement of the image contrast in dim images and simultaneously removed sensor noise. The performance of this simple, dynamic spatial domainfiltering algorithm depends on two parameters that can be estimated by evaluating global image statistics and executing a simple noise estimation method.

*Performance of the NV algorithm using a dim image of a mobile phone camera as input. (A) The original image is black. (B) After automatic histogram equalization sensor noise was amplified. (C) The NV-processed image exhibits a high level of image contrast and contains a low amount of noise. PSNR of C:* 

*25.9 dB. Hartbauer holds the copyright of this picture.*

function "compare\_psnr" offered in the "skimage.measure" library.

(*grey*\_*avg*)]/

[*max*

(*grey*\_*avg*)]} ∗ 9.9

(*grey*\_*avg*)

(6)

**40**

**Figure 2.**

*Performance of the NV algorithm using a dim natural image as input. (A) Noisy image of a village on Mallorca (printed with permission from Buades; see Buades et al. [6]). (B) Noise was amplified after histogram stretching. (C) The output of the NV algorithm yielded a reduced amount of noise (PSNR = 35.3 dB) and shows a higher quality regarding image details and contrast.*

Application of this NV algorithm to an underexposed image that was taken in a very dim room resulted in an output image with a high level of contrast and rather low noise level (see **Figure 2C**). On the contrary, the automatic adjustment of brightness and contrast offered by commonly used image processing software

either produced a rather dark image (similar as **Figure 2A**) or a contrasted image in which sensor noise was greatly enhanced (**Figure 2B**). The adaptive spatial averaging procedure preserved fine image details and object contours, while most noise was removed. This is mirrored in the high PSNR value of 25.9 dB when **Figure 2B** was compared with **Figure 2C**.

The NV algorithm enhanced image contrast and removed noise from the natural image showing a village (compare **Figure 3A** and **C**; PSNR = 35.3 dB), whereas automatic contrast enhancement amplified image noise greatly (**Figure 3B**). In comparison, denoising performed with an improved non local mean algorithm published by Buades et al. [6] removed noise slightly more effective (PSNR = 41.1 dB), but did not improve image contrast.

When Gaussian distributed noise with a standard deviation of 12.75 was added to an image of a bird (**Figure 4A**), the NV algorithm removed noise while retaining many fine image details (**Figure 4B**). This performance is reflected in a high PSNR value of 32.1 dB. The same noisy picture processed with a method that is based on the moving least squares (MLS) algorithm described by Lee et al. [9] resulted in the production of a rather blurry image.

The noisy grey-scale image, shown in **Figure 4C**, contains additive Gaussian noise with a standard deviation of 0.6. The output image of the NV algorithm

#### **Figure 4.**

*Denoising performance of the NV algorithm using grey scale images as input. (A) The image of a bird (from Lee et al. [9]) was degraded by Gaussian distributed noise with σ = 12.75. (B) The NV algorithm removed noise (PSNR = 32.1 dB) and preserved many fine image details. (C) Additive Gaussian noise with σ = 0.6 was added to an image of an alarm clock. The NV algorithm removed noise (PSNR = 27.4 dB) without degrading fine image details (D). The picture was printed with permission from Springer Inc. The picture shown in (C) was printed with permission from Yoon et al. [10] (Creative Commons License).*

**43**

**Figure 5.**

*From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising*

(**Figure 4D**) contains many fine image details and the noise level was reduced by 27.2 dB (PSNR). This denoising performance is very similar to the adaptive total variation minimization-based image enhancement method (ATVM) described by Yoon et al. [10], which is mirrored in a similar PSNR value of

Adaptive spatial averaging as described here can also be used to remove noise from color images (see **Figure 5**). This NV algorithm successfully removed noise from the extremely noisy image showing a candle (**Figure 5A**). Denoising of this image resulted in a PSNR of 32.0 dB (**Figure 5B**), which is similar to the denoising performance of the GSM wavelet denoising described by Portilla et al. [23]. The NV algorithm also removed most noise from the image showing the face of an ostrich in **Figure 5C**, resulting in a PSNR value of 32.7 dB. Interestingly, the resulting image is rather sharp and still contains many fine image details, such as the hairs. In contrast, the novel image denoising method described by Liu et al. [4] created

*The NV algorithm reduced the noise level in extremely noisy color images. (A) Noisy color image of a camera taken at candle light conditions. The NV algorithm removed most noise (PSNR = 32.0 dB) (B). (C) Noisy color image of an ostrich with 10% additive Gaussian noise. (D) Noise reduced output of the NV algorithm* 

*(PSNR = 32.7 dB). Pictures printed with permission from IEEE (see Liu et al. [4]).*

*DOI: http://dx.doi.org/10.5772/intechopen.91911*

30.5 dB.

### *From Insect Vision to a Novel Bio-Inspired Algorithm for Image Denoising DOI: http://dx.doi.org/10.5772/intechopen.91911*

*Biomimetics*

**Figure 2B** was compared with **Figure 2C**.

but did not improve image contrast.

production of a rather blurry image.

**42**

**Figure 4.**

*Denoising performance of the NV algorithm using grey scale images as input. (A) The image of a bird (from Lee et al. [9]) was degraded by Gaussian distributed noise with σ = 12.75. (B) The NV algorithm removed noise (PSNR = 32.1 dB) and preserved many fine image details. (C) Additive Gaussian noise with σ = 0.6 was added to an image of an alarm clock. The NV algorithm removed noise (PSNR = 27.4 dB) without degrading fine image details (D). The picture was printed with permission from Springer Inc. The picture shown in (C)* 

either produced a rather dark image (similar as **Figure 2A**) or a contrasted image in which sensor noise was greatly enhanced (**Figure 2B**). The adaptive spatial averaging procedure preserved fine image details and object contours, while most noise was removed. This is mirrored in the high PSNR value of 25.9 dB when

The NV algorithm enhanced image contrast and removed noise from the natural

When Gaussian distributed noise with a standard deviation of 12.75 was added to an image of a bird (**Figure 4A**), the NV algorithm removed noise while retaining many fine image details (**Figure 4B**). This performance is reflected in a high PSNR value of 32.1 dB. The same noisy picture processed with a method that is based on the moving least squares (MLS) algorithm described by Lee et al. [9] resulted in the

The noisy grey-scale image, shown in **Figure 4C**, contains additive Gaussian noise with a standard deviation of 0.6. The output image of the NV algorithm

image showing a village (compare **Figure 3A** and **C**; PSNR = 35.3 dB), whereas automatic contrast enhancement amplified image noise greatly (**Figure 3B**). In comparison, denoising performed with an improved non local mean algorithm published by Buades et al. [6] removed noise slightly more effective (PSNR = 41.1 dB),

*was printed with permission from Yoon et al. [10] (Creative Commons License).*

(**Figure 4D**) contains many fine image details and the noise level was reduced by 27.2 dB (PSNR). This denoising performance is very similar to the adaptive total variation minimization-based image enhancement method (ATVM) described by Yoon et al. [10], which is mirrored in a similar PSNR value of 30.5 dB.

Adaptive spatial averaging as described here can also be used to remove noise from color images (see **Figure 5**). This NV algorithm successfully removed noise from the extremely noisy image showing a candle (**Figure 5A**). Denoising of this image resulted in a PSNR of 32.0 dB (**Figure 5B**), which is similar to the denoising performance of the GSM wavelet denoising described by Portilla et al. [23]. The NV algorithm also removed most noise from the image showing the face of an ostrich in **Figure 5C**, resulting in a PSNR value of 32.7 dB. Interestingly, the resulting image is rather sharp and still contains many fine image details, such as the hairs. In contrast, the novel image denoising method described by Liu et al. [4] created

#### **Figure 5.**

*The NV algorithm reduced the noise level in extremely noisy color images. (A) Noisy color image of a camera taken at candle light conditions. The NV algorithm removed most noise (PSNR = 32.0 dB) (B). (C) Noisy color image of an ostrich with 10% additive Gaussian noise. (D) Noise reduced output of the NV algorithm (PSNR = 32.7 dB). Pictures printed with permission from IEEE (see Liu et al. [4]).*

patchy regions of homogeneous color, when the same noisy image was used as input. Furthermore, GSM wavelet denoising of this image resulted in image blur.
