You are on page 1of 52

Technical University of Denmark

Introductory project - Earth and Space Physics and Engineering


30110

Speckle reduction of Synthetic Aperture


Radar images

Authors:
Kristian Sørensen
s154443
Supervisor:
Simon Lupemba
Henning Skriver
s153283
Eigil Lippert
s132561

16-06-2017
Abstract
Speckle noise inherent in SAR images weakens the meaningful applications of the SAR.
The reduction of the speckle noise is studied leading to actual filtering algorithms, based
on the early propositions for speckle filtering. To evaluate the performance of the different
algorithms, several parameters are introduced. All parameters are based on statistical
theory and should be well known within the field. The only exception is the EQP devel-
oped by the authors to quantify the quality of the edges. In addition to the parameters,
the analysis builds on the visual interpretation of the SAR images. Conclusively, the
Lee-filter turns out to be superior to the others in terms of speckle reduction and edge
preservation, having only a slight disadvantage in dealing with close targets.

1
Contents
1 Introduction 4

2 General theory 5
2.1 Synthetic aperture radar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 The formed image and its speckle . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.2 The test image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Statistics of the unfiltered test image . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Edges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Image processing 11
3.1 Simple filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.1 A simple average filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.2 Box filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Adaptive filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.1 Frost filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.2 Modified Frost filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2.3 Lee filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Edge Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.1 Ratio operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3.2 Developing an edge quality parameter . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.3 Constant false alarm rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4 Analysis 19
4.1 Box filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Frost filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.3 Modified frost filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.4 Lee filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.5 Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.6 1/VMR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.7 Edge preservation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.8 Run-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5 Discussion 24
5.1 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.2 Edge quality parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

6 Conclusion 27

2
References 28

Appendix 29
6.1 Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.2 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.2.1 localMean.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.2.2 localVariance.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.2.3 FrostFilter.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.2.4 modifiedFrost.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.5 LeeFilter.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.2.6 gammaEdge.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.2.7 CFAR.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.2.8 localMeanMask.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2.9 localVarianceMask.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6.2.10 Colorshow.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.2.11 evalTestImage.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.2.12 loadTestImage.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

3
1 Introduction
This project is concerned with remote sensing in the microwave part of the electromagnetic spectrum,
and especially different approaches to processing of data. Here the data used are images, generated
based on the measurements from a Synthetic Aperture Radar(SAR). One challenge in working with
SAR-images is that homogeneous areas, like the the sea, are distorted from an large amount of noise.
The noise is known as speckle noise, since it makes the images look granulated. In order to increase
the amount of meaningful applications of SAR radar images, the speckle noise has to be reduced.
The overall aim of this project, is to investigate how to reduce speckle noise from the SAR images.
Speckle noise can be reduced through several different filtering algorithms. These algorithms will be
implemented in Matlab, discussed and compared relative to each other. In this regard, two parame-
ters that describes the quality of the filtering techniques, will be introduced. The first parameter for
determining how well the speckle has been reduced in homogeneous areas; the second for how well the
filter preserves the edges of the original image.

The images used here are acquired from the Sentinel -missions through the Copernicus Open Access
Hub 1 offered by the European Space Agency. Using the Sentinel Application Platform(SNAP)2 , it is
possible to modify the data files downloaded from the hub. SNAP is used for calibrating the images,
and cropping them to generate smaller subsets, to lessen the computations needed. An example of a
typical SAR image is seen in figure 1, a subset of this images will be used in the report.

Figure 1: A SAR image of Lolland and Falster captured by one of ESA’s Sentinel satellites. The image is
calibrated and cropped using (SNAP)

1 https://scihub.copernicus.eu/
2 An architecture combining all the Sentinel toolboxes

4
2 General theory
In this section we aim to explain the basic theory behind SAR. This is necessary to understand the
origin of speckle and thus the image processing. For this, a suitable test images for the filter is chosen
and it is discussed how it is representative. The statistics and probability is explained, followed by
an examination of the probability distribution of the speckle intensity. Then statistical properties of
the test images will be examined to justify the theory behind the probability distribution of speckle.
Lastly a general introduction of filters and edges are given.

2.1 Synthetic aperture radar


3
In the following the basics theory supporting the SAR is explained using ”Remote sensing by SAR”
followed by an introduction to the occurring noise called speckle.
A common feature for all active radars is that they transmit an electromagnetic pulse from an antenna
which propagates through vacuum or some medium (for example atmospheric air). The wavelength
of the electromagnetic pulse differs from radar to radar and exhibits different properties. The SAR
radar exploits the microwave band. The optimal wavelength needed depends on the objective since
the atmosphere has different opacity in different wave bands. Some of the microwave bands offers the
advantage of all-weather capability. The SAR is an active sensor meaning it provides its own light
source. All together the SAR is very versatile, being able to give accurate measurements in all kinds
of weather, both day and night. The emitted SAR pulse propagates until it collides with an object
that will reflect the pulse according to the properties of the object(like surface and composition). De-
pending on the reflection, parts of the reflected pulse will be received by the antenna. This pulse is
going to be diminished for three different reasons; The pulse is propagating through space and is going
to decline as 1/R2 , with R being distance. Moreover the reflecting surface is going to disperse the
pulse in different directions meaning that only a fraction is sent towards the SAR and in addition, the
reflected pulse will also decline as 1/R2 .

The SAR differs from other radars in the way that it exploits the reflection along a path taken by a
airplane or, as in most cases a satellite, on which the SAR is placed. As the satellite moves from t0
to t1 , the SAR is transmitting and receiving pulses continuously. Seen in figure 2. At a time t0 the
SAR receives a pulse reflected from the target. At a time t1 the satellite has shifted a distance L. In
this time frame the SAR receives many reflected pulses from the same target at different angles. Due
to the Doppler shift it is possible for the SAR to process all the accumulated signals received from
one specific target, resulting in a better resolution. For this reason the SAR synthesizes an antenna
of length L which compared to the physical size of the actual antenna is a great enhancement. Hence
the name Synthetic Aperture Radar.

2.1.1 The formed image and its speckle

As mentioned in section 2.1, the emitted pulse hits an area of the target. This area consist of different
objects with different shapes, shown to the left in figure 3. When the pulse strikes these different objects
3 Skriver 2015

5
Figure 2: The SAR emits a pulse that propagates at an angle β. In the timespan from t0 to t1 the target is with
in the measurable area and thus is reflecting the pulse back to the SAR. The SAR can then use the Doppler
effect and with the travelling time to synthesize an antenna of length L resulting in higher resolution.

each one reflects a different signal with a different amplitude and phase which interferes constructively
or destructively. Speckle is the result of this interference. The signal received by the SAR is an
accumulation of all of the different signals, resulting in a given intensity. This is illustrated on the
right in figure 3. Consequently, neighbouring pixels may have very different intensities and the image
will therefore look granulated. This being the speckle noise we wish to diminish.
The general approach of diminishing this speckle noise is to take the mean intensity of a homogeneous
area. This build on the assumption that the mean of a homogeneous area represents the true intensity
of the area.

Figure 3: The different signals emitted from the target corresponds to different amplitudes and phases. The
signal received by the SAR is the accumulation of all the different amplitudes and phases as shown. Ei being
the reflection from single object and Etot the accumulated signal (ESA 2017)

6
2.1.2 The test image

The specific aim is to reduce the speckle with a minimal loss special features. This means that only
the speckle should be filtered while edges and point targets 4 should be preserved. We have chosen a
representative subset of a SAR image to test different speckle reduction algorithms . The image is
shown in figure 7. It is a 901x901 pixel image, showing the area near the city Nakskov. It was taken in
June 2016 and it is therefore giving us optimal conditions in regards to vegetation and hence speckle
detection. This image has been chosen since it contains many diverse areas, such as field-, ocean- and
urban areas. Comparing how the different filters for speckle reduction performs on each area, enables
an overall evaluation of the qualities of the filters. The white boxes in figure 7, shows the specific
regions of interest. A number has been designated to each region, and will be used to refer to each of
the different regions. The regions, and the reasoning behind them are given below:

1. Region 1: Ocean
This region is a prime example of a homogeneous area. The intensity is very low and looks dark.
It should be simple to reduce speckle in this region.

2. Region 2: Bright field


This region is homogeneous. The intensity is high. This gives an indication on how well the
speckle reduction works on a bright field.

3. Region 3: Dark field


This region is homogeneous. The intensity is low. Compared with region 2 this gives an indication
of how the different intensities affects the filter.

4. Region 4: Coastline
This region consist of two homogeneous areas, ocean and land, with a clear edge between them.
This region will show if the filter is able to maintain the sharp edge of varying direction at the
coastline.

5. Region 5: Field edges


This region consist of two homogeneous areas, both fields, with a clear edge between them. This
will show if the filter will respond in the same way for edges between fields, as with the edge of
the coastline.

6. Region 6: Urban area


This region is inhomogeneous. It contains many single targets. Region 6 is chosen to investigate
how well the filter will treat a inhomogeneous area like a city. It will show if the filter is able to
preserve single targets.

4 Often the result of structures in the image, as buildings and vehicles which appears as small high-intensity dots on
the SAR-image.

7
Figure 4: The test image with regions shown. It is a SAR image of the area near Nakskov. The white squares
shows the regions of interest.

2.2 Statistics
2.2.1 Probability

Due to the complex circumstances leading up to the actual image output, it is useful to make esti-
mations based on the information available. However this introduces uncertainties, which are best
quantified through probability 5 . In this case, with images containing enormous amounts of pixels,
the point of interest is the behaviour of speckle noise. Even though speckle behaves differently, the
average behaviour can be estimated.
As it turns out, the intensity for the image follows the gamma distribution, as describe later in 2.2.2.
The shape parameter, N is an expression of what the distribution looks like. When using different
values for the shape parameter for the gamma distribution a interesting phenomenon arises. When
N = 1 the distribution resembles the exponential distribution. Moreover, the probability distribution
resembles the Gaussian distribution with increasing values of N. This is shown in figure 5.
The multi look theory for speckle states that speckle is gamma distributed. The shape- and scale
parameters are then given by:
µ2 1 V
N= = , λ= (1)
V VMR µ
With N as the shape parameter and λ the scale parameter. µ is the mean of the pixels, V is the
variance and V M R is an abbreviation for Variance to Mean Ratio. For homogeneous areas:
1
ENL = N = (2)
VMR
ENL is short for Equivalent Number of Looks. This number indicates how many indent measurement
5 Blundell and Blundell 2010, p.18-21

8
Figure 5: The gamma distribution with different shape-parameters, N, and a fixed scale parameter. The red line
represents the exponential distribution with a N=1. The yellow line the gamma distribution when N=4. The
rest with N ≥ 10 resembles Gaussian distributions. In conclusion, with higher values for N, the distribution of
the image approaches the Gaussian distribution.

a pixels is based on. If all pixels in the SAR picture is processed in the same way the different
homogeneous areas would be expected to have the same ENL.

2.2.2 Statistics of the unfiltered test image

To justify that speckle is gamma distributed, histograms of the homogeneous regions of the test image
are shown in figure 6

Figure 6: Histograms showing the distributions of the intensities in regions 1-3. The gamma distribution is
shown with the red curve.

A comparison between the histograms and the gamma plot in figure 6 implies a gamma distribution
in the unfiltered test image. Hence, the filters considered will be based on gamma distributions. If the
ENL is increased, a larger shape parameter would be obtained and so a different distribution. In these
cases it is beneficial to use different methods of filtering based on the Gaussian distribution. Gaussian
distributed filtering will not be described. Moreover, an illustration of 1/VMR is seen in figure 7.
As stated in section 2.2.1, homogeneous areas are expected to have 1/V M R = EN L. This is shown
in figure 7. As it can be seen, the three homogeneous regions have approximately the same value of

9
Figure 7: 1/VMR for the different regions of the image for both VV -and VH polarization.

EN L = 4.5, meaning they indeed are homogeneous areas. Since it is true for both the VH and VV
polarization, the focus will lie solemnly on the VV polarized image6 . Using figure 5 for comparison,
figure 7 also shows that the homogeneous areas indeed follows the gamma distribution.
According to figure 7, region 4-6 have lower values of 1/VMR. This corresponds with a higher variance
as expected.

2.3 Filters
As described in section 2.1.1, speckle noise is a major issue when analyzing images. There are several
different ways of reducing this speckle noise.7 Common for all different filter methods is that they
take the pixel values of the original image and alter them according to the neighbouring pixel values.
8
Simple filters treat all pixels in the same manner. An example of this is the Box filter described in
section 3.1.2. A more advanced type of filters is the adaptive filters. Adaptive filters change the way
it operates based on the local statistics of the pixel it is considering. This means that the adaptive
filters will treat an urban area differently than a field. Two classic adaptive filters are the Frost- and
Lee filters, described in section 3.2.

2.4 Edges
When using a filter in order to minimize speckle noise, information can be lost. An important feature
in images are the edges. The edges of an image is basically a steep local change in intensity of the
pixels and they provide information regarding the shape of the image. Hence, edges are important
features for analyzing images.
Two overall kinds of edges exist; step discontinuities, in which the intensity changes from one area
6 VV is vertical transmit, vertical receive. VH is vertical transmit, horizontal receive. NRC 2014
7 Skriver2015, p.11
8 Grey-scale images. Here the images obtained from SNAP are grey-scale

10
to another area and line discontinuities where there is a line of high intensity, but low intensity on
both sides. Since edges are such an important part of the image-analysis it is necessary to detect and
quantify them. This can be done by comparing the mean values, µ1 and µ2 , of two small adjacent
areas. There exist an edge between the two areas if the mean values are different. This edge can be
quantified in two ways. The first way is by looking at the difference between the mean values. The
edge intensity is then given by:
edged = |µ1 − µ2 |

This method work well on areas with normal distributed noise. If the noise is gamma distributed an
edge intensity based on the ratio will work better:9

µ1 /µ2 − 1, for µ1 ≥ µ2

edger = (3)
µ2 /µ1 − 1, for µ2 > µ1

The edge intensity will turn out to be an important part of the Lee filter and a important tool in
evaluating the performance of the the filters.

3 Image processing
The theory from section 2 is used in the development of filters, an edge enhancement operators and
an edge equality parameter. Here it is necessary to examine the theory behind the individual filtering
algorithms.

3.1 Simple filters


3.1.1 A simple average filter

It is possible to reduce speckle with a simple average filter. The filter creates a new image where
all pixels are assigned a value based on the arithmetic mean of the former pixel value and its four
closest neighbours10 . Each pixel in the new image becomes an average of totally five pixels from the
original image. The implementation of this filter is carried out with the Matlab software, through
matrix operations. Matlab operates fast with matrix calculations, so matrix-operations are generally
preferred over loops. First the image is converted into a matrix where the value of a given element
represents the intensity of the pixel and the index number represents the position of the pixel. An
example of this could be the image in figure 8 and the matrix in equation (4).

0 6 4 2
1 2 6 5
Aoriginal = (4)
2 0 3 2
3 2 1 4

9 Touzi1988
10 We only use four pixels because this makes it simple to explain and easy to show calculated examples.

11
Figure 8: The image corresponding to the values in Aoriginal

Four shifted matrices are generated by adding a row/column of zeroes and removing a row/column
on the opposite side of the matrix.

6 4 2 0 0 0 6 4 1 2 6 5 0 0 0 0
2 6 5 0 0 1 2 6 2 0 3 2 0 6 4 2
A1 = , A2 = , A3 = , A4 = (5)
0 3 2 0 0 2 0 3 3 2 1 4 1 2 6 5
2 1 4 0 0 3 2 1 0 0 0 0 2 0 3 2

The filtered matrix Af is generated by averaging the values of Aoriginal , A1 , A2 , A3 and A4 . Since the
outer pixels are not averaged correctly, the last step is assigning a ”dead” pixel value X.

X X X X
X 3 4 X
Af = (Aoriginal + A1 + A2 + A3 + A4 )/5 = (6)
X 1.8 2.4 X
X X X X

The information loss due to the dead pixels in this example is significant. However, when the filter
technique is applied to the actual SAR images, the loss of information is negligible.

3.1.2 Box filter

The simple averaging filter can be modified such that it also considers the pixel values diagonal to the
center pixel. This means that the averaging will be based on a box of neighboring pixels. The Box
filter calculates the average of all the pixels in the box, and creates a new matrix containing all these
averages. The implementation can be seen in the Matlab-script localMean.m, Appendix 6.2. The
box filtering is carried out by creating several displaced matrices as explained earlier. By taking an
element-wise average of the pixels, a new matrix can be generated. The box size is determined by n
pixels which extents n pixels horizontally and vertically from the center pixel. For an example n = 2
would calculate averages based on the original values contained in a 5x5 pixel window. Each average
value is placed in a new matrix, on the position of the center pixel of the original image. Hence the
Box filter outputs an image matrix of the same size as the input image matrix. As with the Simple
average filter, the outer values are removed by assigning a dead pixel value.

12
3.2 Adaptive filters
As explained in section 2.3, adaptive filters uses local statistics in order to vary the filtering. In the
following, two filters, the Frost -and the Lee filter will be introduced. These filters are among the very
first filters, and are often used as reference for more advanced filters. Furthermore, a modification for
the Frost filter will be introduced.

3.2.1 Frost filter

The Frost filter11 works by assigning the average of the neighboring pixels to a new filtered image. It
corresponds to how the Box filter operates, only this time the average is weighted. The weight is given
by:
wi = exp(−αCc ri,c ) (7)

Where α is a constant that determines the sensitivity. Cc is the speckle index of the center pixel
of the box and ri,c is the distance between the current pixel and the center pixel. This means that
the pixels closest to the center pixel have the highest weight in creating the new pixel value. Cc is
the parameter which introduces the adaptive quality of the filter. Based on the value of Cc the filter
averages differently. If the area of pixels in the current box are homogeneous, Cc will be low and
the averaging of the Frost filters will resemble that of the box filter. If the box on the other hand is
inhomogeneous then Cc will be high and the values of the center pixel will be more or less conserved.
This means that the filter treats homogeneous and inhomogeneous areas differently. The speckle index
for the classic Frost filter, is defined as:

Cc = V M Rlocal (8)

Where V M Rlocal is the VMR of the current window. This means that the filter adapts to the pixel
values of the current box. In this way the pixels in areas with low VMR are strongly filtered, while
pixels in areas with high VMR are preserved. The areas with low VMR are often homogeneous areas
and the areas with high VMR mostly inhomogeneous areas, this can be seen in figure 7. The final
result is a reduction of speckle noise, while edges and single targets, are only distorted a little.

3.2.2 Modified Frost filter

The Frost filter can be optimized by introducing a modification to the Frost filter. This is done by
redefining the speckle index to depend on a threshold, T0 . The speckle index is defined as

V M Rbox − 1 , for V M Rbox ≥ 1/T0

Cc = T0 (9)
0,

for V M Rbox < 1/T0

This definition of the speckle index means that every area with a 1/VMR-value larger than the threshold
will be box-filtered. A weighted average will be given to areas with 1/VMR values smaller than the
threshold. For homogeneous areas 1/VMR is the same as ENL. The test images has an ENL around
4.5 as seen in figure 7. An expected value for the threshold is therefore between 2 and 4. The threshold
is based on the CFAR method explained in section 3.2.3.
11 Frost 1982

13
3.2.3 Lee filter
12
The Lee filter is also an adaptive filter. It uses local statics to compute the new pixel value. The
Lee filter does not exploit the mean and the variance of the entire window, but only a part of the
window defined by a mask. The masks are chosen so that the statistics for the pixel are based on the
area of the window that resembles the pixel the most. The remaining dissimilar area of the window
is excluded from the statistics. This performs well when the window overlaps with an edge. As an
example, imagine an image containing a bright and a dark field, separated by a vertical edge. If the
pixel in the bright field near the edge13 is considered. The window of this pixel would cover both fields,
but since the pixel resembles the bright field, a mask is chosen so that the statistics will be based on
the bright field. This also means that the mask will exclude the dark field from the statistics. Hence
the appropriate mask as seen in figure 9, would be 0 or 4, depending on the position of the bright field.

Figure 9: The masks shown for a 7x7 window(n=3). They can easily be expanded to a 9x9 window(n=4). The
white area is used for computing the statistics, the dark area is not. (Lee 1980)

Lee’s original filter uses a 7x7 window but we have modified the algorithm to work with 9x9. The
first step is to identify the mask for each pixels. This is done by dividing the widow into nine 3x3
subsets. In if n = 3 these subsets will overlap but if n = 4 then there will be no overlapping. The mean
of each subset is then calculated and denoted as in figure 10. It is then possible to find the appropriate
mask by comparing the different mean values. There are two ways of doing this. There is the difference
based which Lee originally used. Here the absolute difference between the boxes is compared. The
direction of the edge is given by the direction where two opposite means have the maximum difference.
Referring to figure 10, an example is if |m12 − m32 | > |m11 − m33 |, |m12 − m32 | > |m13 − m31 | and
|m12 −m32 | > |m21 −m23 |. Then the window contains a horizontal edge and mask 2 or 6 is appropriate.
The final mask is found by checking if m22 is closest to m12 or m32 . If |m22 − m12 | < |m22 − m32 |
then mask 2 is assigned to the pixel, otherwise mask 6 is assigned. The second method is the ratio
based. Here the ratios between the mean values of the boxes are compared. This method should be
more suitable for SAR image since speckle noise is multiplicative.14 The direction of the edge is given
12 Lee 1980
13 Where the bright and dark field meet
14 Increasing speckle noise with increasing pixels intensity.

14
by the direction where the ratio between two opposite boxes is the greatest. For example, if
max(m21 , m23 )/ min(m21 , m23 ) > max(m11 , m33 )/ min(m11 , m33 ), max(m21 , m23 )/ min(m21 , m23 ) >
max(m12 , m32 )/ min(m12 , m32 ) and max(m21 , m23 )/ min(m21 , m23 ) > max(m31 , m13 )/ min(m31 , m13 )
Then the window contains a vertical edge and mask 0 or 4 is to be used. The final mask is then
chosen by looking at the ratios between m22 and the other boxes. If max(m22 , m21 )/ min(m22 , m21 ) <
max(m22 , m23 )/ min(m22 , m23 ) then mask 4 is assigned to the pixel. Alternatively, mask 0 is assigned.
This is done in MaskDetect.m as shown in appendix 6.2. Now all pixels have assigned a mask, but the

Figure 10: The window is divided into subsets

masks are not necessarily in the homogeneous areas. To use the statistics of the entire 9x9 window
in the homogeneous areas a threshold is needed. The threshold should mark the pixels within the
homogeneous windows and assign them the mask ”-1”, which is the equivalent to no mask.15 The
threshold is based on the filtering coefficient calculated for the entire window and the CFAR method
16
explained in section 3.2.3. The filter coefficient is given by:
Vlocal ENL − µ2local
k= (10)
Vlocal (ENL + 1)
All pixels with a k value under the threshold is then assigned the mask -1. Now all pixels are assigned
a mask. Homogeneous areas have -1 and the rest, the edges, have a mask ranging from 0-7. Next, the
local variance and mean is calculated based on the pixels within the masks17 . This is used to compute
a new filter coefficient
Vmask ENL − µ2mask
kmask = (11)
Vmask (ENL + 1)
Then the filtered picture is given by

ImLee = µmask + kmask (Imoriginal − µmask ) (12)

Where ImLee is the new pixel value, µmask the mean of the mask, k the filter coefficient and Imoriginal
the original pixel value.

3.3 Edge Detection


Edge detection is, in much the same way as filtering, an algorithm containing two steps. First edge
enhancement and secondly thresholding. But, as mentioned in section 2.1.1, non-filtered images contain
15 Mask 0-7 are already in use. Hence, all other numbers could be chosen for ”no mask”.
16 ESA 2017
17 This is done using the scripts localMeanMask.m and localVarianceMask.m

15
a lot of speckle noise. For this reason, an appropriate filtering algorithm is executed before enhancing,
and hence removing the noise.18 This will hopefully avoid the false positives. 19
When filtering the
noise an unavoidable loss of the edges is present. Thus, one should decide on a compromise between
edge strength and noise reduction.
After filtering, an edge enhancement is carried out. Next a thresholding is performed. Meaning the
remaining image only has an acceptable amount of noise. This will be further explained in section
3.3.3. Different edge enhancement operators exists. The pixels in the homogeneous areas of the filtered
images should still be gamma distributed, consequently an edge operator suited for gamma distributed
images are chosen.

3.3.1 Ratio operator

The speckle noise is multiplicative and the pixel intensities are gamma distributed. As a consequence,
the edge detector developed uses the ratio between two areas, instead of the difference. This operator
works by creating a new image, where all the pixels are assigned new values. This operator looks at a
3x3 window of the image amplifying the changes in intensity, in order to highlight the edges. It looks
for edges in the vertical direction and in the horizontal direction separately. This can be seen in table
1.
To determine the edges in the vertical direction, γY is placed concentric with the given pixel followed
by an element wise multiplication meaning the element from γY is multiplied with the corresponding
value from the image. Then a summation is performed with the values in γr and γl respectively. A
ratio between these sums is carried out according to equation (3). The same is done in the horizontal
direction, but with a ratio between the top, γt and the bottom pixels, γb . The final edge value is then
given by Pythagorean theorem: q 
Aγ = (AγX )2 + (AγY )2 (13)

A sample computation is carried out as follows. Given an image with intensities corresponding with
the values of matrix Aoriginal in equation (4), the vertical and horizontal edge-operated matrix will
have the values as shown in equation (14):

1 1
1 1 1 γt
1 1
γY = , γX =
1 1
1 1 1 γb
γl γr

Table 1: γY consists of a ratio between the summation made from γl and γr respectivly.

X 9 0.14 X X X X X
X 3.33 0.13 X 2 1 1.4 0.2
A γY = , AγX = , (14)
X 0.67 1.75 X 0.67 0.5 0.86 1.2
X 0.25 2 X X X X X
18 The edge enhancement is also shown on the original image to compare them.
19 False positives meaning high intensity speckle noise which resembles edges but are not.

16
An example on the calculation can be given for Aoriginal (2, 2).

γY l (2, 2) = 1 · 0 + 1 · 1 + 1 · 2 = 3, γY r (2, 2) = 1 · 4 + 1 · 6 + 1 · 3 = 13
The edge value in the y-direction is then found using equation (3)
13
− 1 = 3.33
AγY (2, 2) = (15)
3
Giving the element a new value of 3.33, as it can be seen in equation (14). Doing this with both the
horizontal- and vertical direction and combining them using equation (13) gives the matrix as shown
in equation (16).20

X X X X
X 3.48 1.40 X
Aγ = (16)
X 0.83 1.95 X
X X X X

3.3.2 Developing an edge quality parameter

In addition to removing speckle from the original image, a good filter should also preserve the edges
originally found in the SAR image. To evaluate how well a given filter performs in relation to preserving
the edges, an edge quality parameter21 is introduced.
To begin with, the definition of a well preserved edge is introduced. Edges are found where one type
of area transitions to another one, as an example the transition from a dark to a bright field. The
lines found in the edge enhanced image describes this transition22 . The characteristics of the lines
are the basis for analyzing the edge preservation. It follows that a well preserved edge will appear as
a line resembling the transition in the original image. In other words, if there is a great difference
in neighboring pixel intensities, like in region 5, there is a localized transition and hence the line is
expected to be thin and intense. For a smoother transition, a broader less intense line is expected in
the edge enhanced image.
After the filtering process, noise is still found in the homogeneous areas. When carrying out the edge
enhancement process, some of that noise will be treated as edges and still appear on the edge-enhanced
image. This distortion of the image has to be addressed in order to develop a meaningful edge quality
parameter. To reduce the amount of false edges, edges resulting from noise, a threshold is introduced.
The value which will be used for the thresholding is the CFAR, as explained in section 3.3.3.
The image that remains contain only an acceptable amount of noise. The Box filter is expected to be
the worst filter in terms of preserving edges because it is nonadaptive and treats edges the same way as
homogeneous areas. Consequently the remaining filters described in the report, should preserve edge
better.
The parameter is exclusively based on region 1-5, since the expected results from the urban region
are uncertain. Better edges are expected to have higher intensities and thinner lines. We define the
Edge Value 23 as the average intensity of the nonzero edge pixels:
20 The following calculation is made with the assumption that deadpixel=X
21 Abbreviated EQP in the following
22 Images of this is shown in the analysis.
23 Abbreviated EV in the following

17
P
I
EV = (17)
N
Where I is the intensity, and N is the number of nonzero pixels. Noise that has survived the
thresholding will affect the result, and so the EV in the edge regions, region 4 and 5, should be seen
in relation to the EV in the homogeneous regions, region 1-3. The final result is the EQP taken as
the ratio between EVedge and EVhom :

EVedge
EQP = (18)
EVhom
This describes how well the edges are preserved compared to noise present in the image. The EQP
resembles a signal to noise ratio. A good edge would be expected to give a high EVedge and therefore,
the EQP should increase.

3.3.3 Constant false alarm rate

Constant False Alarm Rate, abbreviated CFAR, is based on the histogram of the pixel values in all the
homogeneous regions. We have chosen to have a CFAR of 1%, hence the threshold is calculated as the
upper 1 % of the pixels in a histogram, as sketched in figure 11. This means that the amount of pixels
above the threshold will vary from histogram to histogram, but the percentage will stay constant. It
has many applications, but in this project it is used as a consistent method for determining reasonable
thresholds.24

Figure 11: This graph illustrates the CFAR threshold. The blue line corresponds to the distribution. The red
line illustrates the 1% mark. Everything on the left side is removed.

Theoretically a probability distribution can be fitted to the data in question. By calculating the
cumulative probability distribution it is then possible to determine the 1% mark. This approach is
not used here, since the distributions does not necessarily fit the theoretical distributions available.
Instead a more practical approach is taken and by ordering the pixels in a vector of increasing order
and finding the index closest to the 1% mark.25 This approach is carried out in the script CFAR.m, as
seen in appendix 6.2
24 For the Modified Frost filter, the Lee filter and for the Edge Quality Parameter.
25 The uncertainty of the index is negligible.

18
4 Analysis
In order to analyze the filters and operators in the best possible way, we start of by a short analysis of
the different filters. Here, the input parameters used in the later comparison are determined. After the
input parameters are determined the different parameters of the filters such as the the mean, 1/VMR
and edge preservation are examined. Furthermore, the different runtimes for our filters are taken into
consideration. Consequently, the different strengths and weaknesses of the filters will be shown, this
leading to a discussion of our results in which we compare the different filters.
The window size n = 4 is chosen to compare the filters. This corresponds to a 9x9 window. If a value
for n is not specified in a figure then it is because n = 4 is used. Figure 12 illustrates the effects
of all the filters on region 5. In the following, region 5 is used due to the fact that it consist of two
homogeneous areas as well as a rather sharp edge. The filtering on the other regions can be seen in
figure 22, appendix 6.1.

Figure 12: Illustration of the filtering performed by the different filters on region 5, showing filtering on homo-
geneous areas and a sharp edge.

4.1 Box filter


Starting with the box-filter as described in section 3.1.2 and implemented in localMean.m, Appendix
6.2. The box filter takes an average of all the pixels in the window, without taking edges into consid-
eration. Thus edges and homogeneous areas are blurred out equally. Changing the values of n changes
the size of the kernel and hence a different avenging is acquired. A larger value of n corresponds with a
larger kernel and therefore a better approximation of the mean, and worse approximation of the edges,
is archived. In conclusion, the box filter performs well with homogeneous areas and poor in regards to
edges.

4.2 Frost filter


The Frost filter, as described in section (3.2.3) and implemented as FrostFilter.m in Appendix 6.2
In figure 12 one can see the filtering performed by the Frost filter. Increasing either the sensitivity, α
or the window size leads to smaller weight wi and consequently less filtering. The value of α is then
chosen from analyzing Frost filtered images with different values of α. Looking at figure 20 in appendix
6.1 one can see different Frost filtered images. A higher value of α leads to higher intensity edges,
but more noise close to the edges. When choosing higher values of α, the filtering is decreasing, and

19
noise begins to appear in the homogeneous areas. Observing figure 20 leads to a compromise between
filtering and edge preservation and thus a α =1 is chosen. The filtered image shown in figure 12.

4.3 Modified frost filter


With the speckle index defined in equation (9), the modified Frost filter offers the opportunity to
select a threshold. We have based the threshold on the CFAR method used on the VMR values in the
homogeneous areas. A marginal on 1 % is used. This yields a T0 = 3.5. The effect of the threshold is
visualized in figure 13. Using this threshold, a value for α can be found. This is done as for the Frost

Figure 13: The thresholds for modified Frost- and Lee filter are visualized. Modified Frost is shown to the left
with a threshold T0 =3.5, the blue areas are above the threshold. Lee is shown on the right. Values below the
threshold, corresponding to no mask, are colored black. Moreover the other types of mask are shown as, mask
1=light green, 2=red, c=cyan, 4=magenta, 5=blue, 6=white, 7=yellow and 8=dark green.

filter. Figure figure 21 illustrates how α affects the filtering. A compromise between edge strength and
speckle noise reduction gives a value of α=3.5.

4.4 Lee filter


The Lee filter, as described in section 3.2.3 can reduce speckle noise near the edges without blurring it
out. The options of computing the difference or the ratio in defining the masks offers slightly different
results. Since the SAR image is gamma distributed, the ratio option is chosen, the difference between
these two can be seen in figure 23 in appendix 6.1. As with the modified Frost filter the threshold
is determined by using the CFAR on the filtering coefficient. This yields a threshold of T0 = 0.395.
LeeFilter.m can operate with n = 3 and n = 4, but n = 4 is desirable over n = 3 since this reduces
the error when finding edge directions. Using 8 different masks as defined from Lee and a no-mask
value. It would be possible to modify the filter by defining more or different masks but this would also
require some changes to the way the masks are found.

20
4.5 Mean
One parameter of importance for the filters is its ability to maintain the original mean value of the
different regions. Figure 14 shows the effect the different filters have on the mean values of the different
regions. All of our filters preserve the mean value rather well in the first 5 regions. The box and the
Lee filter causes a large deviation in region 6. This is probably because they both try to reduce speckle
in the urban area. There is a lot of high intensity targets in the urban area so an attempt to filter
it can easily change the mean value. The other filters, Frost and modified Frost, have only a small
deviation in region 6, this is because they are assigning the same, unfiltered value to the pixel.

Figure 14: Graph of the mean values in the different regions of the test image.

4.6 1/VMR
Using 1/VMR, it is possible to quantify the ability of the filter to reduce speckle as described in
the general theory. A reduction of speckle in the homogeneous areas would of cause also reduce the
variance in the area. This would lead to an increased 1/VMR. This corresponds to a raise in ENL.
Because ENL is linked to the shape parameter N this would cause the distribution in the homogeneous
areas to resemble a Gaussian distribution. Figure 15 illustrates the different values for 1/VMR. It
is clear to see a big increase in 1/VMR in the homogeneous areas. This indicates a good reduction
of speckle. Looking at region 4 and 5 an increase in 1/VMR is seen, this is because both regions
consists of to homogeneous areas and the variance is reduced in each area. It is only the box filter
which has a significant effect on region 6. This is because the adaptive filters recognizes this region as
inhomogeneous.

4.7 Edge preservation


The basis for the analysis is the Edge Quality Parameter as described in section 3.3.2, supported by
the visual results of the edge enhancement.

21
Figure 15: The graph on the left illustrates the common logarithm of 1/VMR in the different regions of the test
image . On the right, 1/VMR for the homogeneous regions are shown. The ENL for Box- and modified Frost
filter respectively in region 3 are displayed on top of each other.

The visual results of the edge enhancement are seen in figure 16. Both before and after the threshold,
it is clear that the edges become more localized and intense when going from left to right in figure 16.
Table 2 presents the threshold26 , EVedge , EVhom and EQP of the different filters. It should be noticed
that if the EVedge of the original image is ignored, the EVedge has an increasing pattern corresponding
to the visual impression of how well the filters perform. However the fact that the original image holds
such a high EVedge indicates that the speckle affects the EVedge positively. EVhom describes the noise
remaining in the homogeneous regions after the threshold is used. This corresponds well with the fact
that the Box- and the modified Frost filter holds the lowest EVhom , since these are good at reducing
speckle. Another reason for the EVhom in the homogeneous areas might be the point targets that are
non distinguishable from the surrounding speckle. From table 2, it is seen that the EQP fixes the
issue with the very high EV values for the original image, since the effect of false edges as a result
from speckle is taken into consideration. It is seen that the original image has the lowest EQP, and
the four filters have higher EQPs. The modified Frost filter has the highest value, and the Lee filter
has the second highest.
It is noticed that there is a discrepancy between the values in table 2 and the visual impression.
From the visual result the Lee filter appears to be the filter that preserves edges best. On the other
hand the EQP favors modified Frost. This discrepancy will be discussed in detail later. The images
for region 4 is shown in figure 25 appendix 6.1, and shows the same general tendencies as described
above.

4.8 Run-time
In order to evaluate the filters, run-times are into consideration. The focus has been on the ability of
the filters to reduce speckle as well as preserve the edges. For this, a small test image has been used.
When using larger images, the run-time is expected to increase. Figure 17 displays the run-time with
increasing quadratic data-sets.
As it can be seen in figure 17, the Lee filter has the highest run-time and the box has the least
26 A threshold for the edge enhancment

22
Filter Original Box Frost Modified Frost Lee
27
Threshold 3.1568 0.2345 0.2621 0.2366 0.4433
EVedge 4.2781 0.4197 0.5854 0.6603 1.4175
EVhom 3.9179 0.2782 0.3238 0.3129 0.7387
EQP 1.0919 1.5089 1.8076 2.1102 1.9189

Table 2: In the above table the different values used to determine the edge quality parameter are shown. The
values in the table are based on the edge enhanced images.

Figure 16: Here edge enhancement is shown carried out on region 5. The first row of images shows the edge
enhancement on the filtered image. The row of images below shows the edge enhanced images with the intensities
below the edge threshold removed.

Figure 17: These graphs displays the run-times for our filters. On the left, a random noise image is made.
This is simulated speckle. On the right, areas of same size is chosen from our own image

run-time. Furthermore, it can be seen that the Lee- and modified Frost filter almost have a constant
run-time. With larger images, computing the Frost filter uses more time than computing the modified
Frost filter. There is a decline in run-time. Seeing this on both the simulated- and our image leads us
to believe this is due to how Matlab operates, and not the change in homogeneous areas.

23
5 Discussion
In order to compare the filters to each other, the input parameters will be kept constant. This enables
the advantages and drawbacks of the different filters to be discussed relative to each other.

5.1 Comparison
All the filters reduces the speckle in the homogeneous areas, but looking at figure 15 there is a difference
in the variance-to-mean ratio. The Box filter reduces the speckle noise the most, closely followed by
the modified Frost filter. The remaining filters reduces speckle to a lesser degree. Considering the edge
enhanced images in figure 16 the poor edge preserving abilities of the box filter becomes clear. The
box filter blurs the edges between the fields. The adaptive filters handles this task better. The Frost
- and modified Frost filter leaves the pixels near the edges more or less intact. The Lee filter performs
even better, reducing the speckle all the way up to the edge, creating a clear and continuous edge. The
adaptive filters are clearly preferable since they can reduce the speckle significantly while preserving
the edges. The EQP shows that the modified Frost filter should have the best edges which does not
match the visual evaluation. It is therefore chosen to put emphasis on the visual evaluation, where
the Lee filter surpasses the other filters. Looking at region 6, in figure 18 it is seen that the adaptive
filters preserve point targets in general. However, the Lee filter has a slight tendency to connect close
distinct targets into one target. The Lee-filter performs well with edges between unalike areas, but it is
insensible to thin lines with similar areas around it. As an example the Lee Filter would not see small
roads between to identical fields. This is only an issue for smaller details, more specifically line-edges
smaller than three pixels28 . So even though the Lee filter performs well with edges, the result in the
urban area, where many target are only separated by a few pixels, is poor compared to the modified
Frost filter.

Figure 18: Top: Illustration of the filtering performed by the different filters on region 6. Bottom: Zoom in
view of the targets in the bottom of region 6

Considering the results, the Lee filter is the best at speckle reduction in rural areas. It reduces
28 This is due to the size of the subsets used to determine the masks. The subsets are 3x3 so all lines thinner than 3
pixels have unintended effects on the mask detection

24
speckle and performs well with edges. One flaw is its performance regarding point targets. The
modified Frost filter would probably perform better in semi urban areas or in detecting close targets
separately because of its gentle attitude towards point targets.

5.2 Edge quality parameter


As presented in the analysis, there exist a discrepancy between the visual interpretation of the edge
enhanced images, and the values given in table 2. The Lee filter appears to be best at creating intense
localized edges in the edge enhanced image. However the EQP shows that the Modified Frost filter
should be the best. By comparing the edge enhanced images, with different intensity intervals as seen
in figure 19, it is possible to investigate the reason for the discrepancy. Even though the Lee filter
generates continuous sharp edges it also creates false edges of red interval intensity in the homogeneous
areas. Compared to the other filters, Lee enhances these false edges more than the others. This is
why the modified Frost filter gains a higher EQP. It is difficult to develop an edge parameter that is
not affected by the noise level of the image. As an alternative it was tried squaring the edge enhanced
images before computing the EQP, this also proved unsuccessful since modified Frost also contains
high intensity edges.

Figure 19: The following image displays the different intensities of the pixel values after a thresholding. Inten-
sities in the homogeneous area are below the threshold, giving them the black color. The other intensities have
the following colors; ]0; 0.5]= light green , ]0.5; 1]= red , ]1; 2]= cyan , ]2; 5]= magenta ]5; 10]= blue.

Another way to work around the issue of the speckle affecting the edge parameter was investigating
whether connected components in the image could substitute the number of pixels in calculating
EV . Connected components refers to sequences of neighboring nonzero pixels. As an example eight
nonzero pixels could make up one intact edge, that is one connected component. Alternatively the
eight pixels could also be grouped in two distinct edges, and hence two connected components. Since
Lee apparently creates longer connected components, that is longer continuous edges, Lee should hold
the lowest amount of connected components. If the EV instead was defined as the sum of intensities
divided by the number of components, more continuous intact edges would result in a higher EV .
However this would not grant the Lee filter the highest score in edge preservation. As mentioned
before the Lee filter creates more high intensity edges in the homogeneous areas, and the total amount
of connected components will still be high, yielding a low ratio between intensity and number of
components.
Setting a threshold based on a constant numerical value, in contrast to the CFAR, was also tried. For

25
one, the obvious drawback of this approach is the loss of a generality for determining the threshold.
The second drawback was that it did not improve the results remarkably.

5.3 Method
To continue the discussion of the different filters, a brief overview of the method is discussed. Some
of the procedures have been rather practical in order to move forward. An example is the method of
defining the sensitivity, α for the Frost- and modified Frost filter respectively. This was done with a
visual analysis. A more objective technique is define a desired parameter value, such as 1/VMR, in
order to calculate a value for α. This would yield a more general value.
In addition to the threshold for the Lee filter, as defined from the CFAR, a second maximum threshold
could be introduced, this could ensure that fewer narrow edges would be seen as connected dots.
Obviously, a change in the CFAR would contribute to a different filtering. Since the homogeneous
regions are rather small, a CFAR below 1 % would lead to a non-representative value. A CFAR below
1 % could be a good choice, if the areas were larger. Another changeable value is the window size, as
defined by n. Higher values of n could be examine to improve the filters, an example of this can be
seen in figure 24, where different kernel sizes are used. With higher values of n, a better homogeneous
filtering is made.
Throughout the report, a real SAR image has been used. This proves to be quite cumbersome in the
development and testing of filters. A alternative approach could be to create generate artificial images,
with clear edges and completly homogeous ares. Speckle noise could be simulate using Matlab and
added to the image. This could help to avoid the high intensity peaks in the homogeneous region.
These peaks have the possibility of being both speckle noise or an small object. After using these
artificial images in the development of filters, the filters can be evaluated on a real SAR image. The
SAR image seen in figure 7 offers the opportunity of dealing with different types of challenges. If the
focus was on one specific challenge, such as the ability to preserve edges or single targets, a different
SAR image with different properties29 could be used.
Continuing the work presented in this project, it is possibility to continue the work in different ways.
Developing new filters or operators are an opportunity, but it is also possible to use the filtered images.
For instance, it is plausible to detect changes in certain areas (change detection), using different images.
Moreover, using different filters, one can classify different areas according to their composition and
thus separate fields containing different vegetation.

29 different fields, vertical/horizontal edges ect

26
6 Conclusion
The main objective of this report have been to implement basic filter algorithms and assess their
strengths and weaknesses. This was done evaluating the performance of the different filters, based on
the parameters: 1/VMR, mean and the EQP. In addition the visual analysis supported the evaluation.
The parameter for the speckle reduction 1/VMR, functioned well and produced results consistent to
the visual analysis. The Edge Quality Parameter developed, showed a significant discrepancy compared
to the visual analysis. Developing a parameter corresponding to the visual analysis was not successful.
The results of these evaluations shows that the Lee filter generally performs better. It reduces the
speckle significantly and preserves edges well. The drawback of the Lee filter is the way it treats thin
line edges. In terms of separating close targets, the modified Frost outperforms the Lee filter.
To sum up, when working with areas containing many close targets, intensities peaks the modified
Frost filter is preferable. Investigating entirely homogeneous areas, filtering should be carried out with
the Box filter. For images containing both homogeneous and inhomogeneous areas, the optimum filter
is the Lee filter.

27
References
Blundell, Stephen J. and Katherine M. Blundell (2010). Concepts in thermal physics, 2. edition. 2nd ed.
Great Clarendon Street, Oxford OX2 6DP: Oxford University Press. isbn: 9780199562097.
ESA (2017). Speckle filtering.
Frost et al. (1982). “A model for radar images and its application to adaptive digital filtering of
multiplicative noise”. In:
Lee, Jong-Sen (1980). “Refined filtering of image noise using local statistics”. In:
NRC, Natural Resources Canada (2014). Polarization in radar systems. Visited on 31th of May 2017.
url: http://www.nrcan.gc.ca/node/9567.
Skriver, Henning (2015). “Remote Sensing By SAR”. In:
Touzi, Ridha et al. (1988). “A statistical and geometrical edge detector for SAR iamges”. In:

28
Appendix
6.1 Figures
The following appendix contains the illustration reffered to in the report.

Figure 20: Upon deciding the value for the sensitivity for the Frost filter, a, the following images was made
with a constant n=4. Different a values gives different images. With a=1, a compromise between good edges
and little noise is gained.

29
Figure 21: Upon deciding the value for the sensitivity for the modified Frost filter, a, the following images was
made with a constant n=4 and threshold from CFAR=1 %. Different a values gives different images. With
a=3.5, a compromise between good edges and little noise is gained.

30
Figure 22: The following image displays all regions filtered with all filters. The following values are used; n=4,
af rost =1, amf rost =3.5 and ENLLee =4.5.

31
Figure 23: The following images displays the difference in designating masks for the ratio and difference
option. At the right, ratio is used. Here, the edges have at better, continuous layering that on the left, with
the difference. Values used are n=4, ENL=4.5. 1=light green, 2=red, c=cyan, 4=magenta, 5=blue, 6=white,
7=yellow, 8=dark green, and lastly, -1=black. As expected, the homogeneous areas, with no edges, are black.

Figure 24: This figure shows the different filtering with different values of n.

Figure 25: Here edge enhancement is shown carried out on region 4. The first row of images shows the edge
enhancement on the filtered image. The row of images below shows the edge enhanced images with the intensities
below the threshold removed.

32
6.2 Code
The following appendix contains all the necessary code to reproduce our results.

6.2.1 localMean.m

1 function E = localMean ( Image , n , deadpixel ) ;


2 % The following function calculates the local average .
3 %
4 % input : Image = the givin image one wish to filter
5 % n = Number of pixels on each side of the center pixel .
6 % deadpixel = gives the image deadpixels
7 % output : E = matrix with local mean values for each pixel
8 %
9 % Example : localMean ( img , 4 , ’on ’) ;
10 % filters the image ’img ’ vil a 9 x9 kernal
11 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
12 %
13

14 if nargin == 2
15 deadpixel = 0;
16 end
17

18 dimensions = size ( Image ) ; % dimensions of input matrix .


19 N = (2* n +1) ^2; % Number of pixels
20 deadpixel = 0; % Variable for removing edge pixels .
21 E_sum = 0; % Empty array for mean values .
22

23 % For each iteration the array is moved one step in the given direction . For
24 % each iteration all the current mean are calculated , and added to E_sum .
25 % Iterations works its way from left to right in the array .
26

27 for k = -n : n
28 % Horizontal displacements :
29 % moves element to the left , adds zeros on the left , if k is on the
30 % left of the center array ( - n ) .
31 if k <0
32 Eh = padarray ( Image (: , 1: dimensions (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
33 end
34

35 % moves element to the right , adds zeros on the right


36 if k >0
37 Eh = padarray ( Image (: , 1+ k : dimensions (2) ) ,[0 k ] , ’ post ’) ;
38 end
39

40 % when reaching the center element - do nothing .

33
41 if k == 0
42 Eh = Image ;
43 end
44

45 for i = -n : n
46 % Vertical displacements :
47 % moves elements up , adds zeros above
48 if i < 0
49 Ev = padarray ( Eh (1: dimensions (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
50 end
51

52 % moves elements down , adds zeros below


53 if i > 0
54 Ev = padarray ( Eh (1+ i : dimensions (1) ,:) ,[ i 0] , ’ post ’) ;
55 end
56

57 % when reaching the center element - do nothing .


58 if i == 0
59 Ev = Eh ;
60 end
61 % adds weights to E_sum
62 E_sum = 1/ N .* Ev + E_sum ;
63

64 end
65 end
66

67 if deadpixel == ’ on ’;
68 Image ( dimensions (1) -n +1: dimensions (1) ,:) = 0;
69 Image (1: n ,:) = 0;
70 Image (: , dimensions (2) -n +1: dimensions (2) ) = 0;
71 Image (: ,1: n ) = 0;
72 end
73

74 E = E_sum ;
75 end

6.2.2 localVariance.m

1 function V = localVariance ( Im , localMean , n ) ;


2 % The variance will be given locally for each pixel in a matrix of dimensions
3 % " dim " based on the input image .
4 % input : Image = the givin image one wish to filter
5 % n = Number of pixels on each side of the center pixel .
6 % localMean = input from the function localMean . m
7 % output : V = matrix with local variance values for each pixel

34
8 % Example : localVariance ( img , localMean , 4) ;
9 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
10

11 dim = size ( Im ) ; % dimensions of input matrix .


12 N = (2* n +1) ^2; % Number of pixels
13 V_sum = 0; % Empty array for variance values .
14 for k = -n : n
15 % moves element to the left , adds zeros on the left , if k is on the
16 % left of the center array ( - n ) .
17 if k <0
18 Vh = padarray ( Im (: , 1: dim (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
19 end
20 % moves element to the right , adds zeros on the right
21 if k >0
22 Vh = padarray ( Im (: , 1+ k : dim (2) ) ,[0 k ] , ’ post ’) ;
23 end
24 % when reaching the center element - do nothing .
25 if k == 0
26 Vh = Im ;
27 end
28 for i = -n : n
29 % Vertical displacements :
30 % moves elements up , adds zeros above
31 if i < 0
32 Vv = padarray ( Vh (1: dim (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
33 end
34 % moves elements down , adds zeros below
35 if i > 0
36 Vv = padarray ( Vh (1+ i : dim (1) ,:) ,[ i 0] , ’ post ’) ;
37 end
38 % when reaching the center element - do nothing .
39 if i == 0
40 Vv = Vh ;
41 end
42 % For each step , the variance is calculated for each pixel ,
43 % based on the current value , and the mean of that pixel .
44 V_sum = 1/ N .*( Vv - localMean ) .^2+ V_sum ;
45 end
46 end
47 V = V_sum ;
48 end

6.2.3 FrostFilter.m

1 function FrostImages = FrostFilter ( Im , n , a )

35
2 % The following function filters the image with the adaptive Frost filter .
3 %
4 % input : Image = the givin image one wish to filter
5 % n = Number of pixels on each side of the center pixel .
6 % output : a = sensitivity
7 %
8 % Example : Frostfilter ( img , 4 , 2.2) ;
9 % filters the image ’img ’ vil a 9 x9 kernal and a sensitivity of
10 % 2.2.
11 %
12 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
13 %
14 dim = size ( Im ) ; % dimensions of input matrix .
15 deadpixel = 0;
16 % % Local values
17 E = localMean ( Im , n ) ;
18 V = localVariance ( Im ,E , n ) ;
19 Speckle_index = V ./ E .^2; % local spekle index
20 clear V E % clear up memory
21

22 % % Frost filter code


23 A_sum = 0;
24 weight = 0;
25 for k = -n : n
26 % Horizontal displacements :
27 % moves element to the left , adds zeros on the left , if k is on the
28 % left of the center array ( - n ) .
29 if k <0
30 Ah = padarray ( Im (: , 1: dim (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
31 end
32

33 % moves element to the right , adds zeros on the right


34 if k >0
35 Ah = padarray ( Im (: , 1+ k : dim (2) ) ,[0 k ] , ’ post ’) ;
36 end
37

38 % when reaching the center element - do nothing .


39 if k == 0
40 Ah = Im ;
41 end
42

43 for i = -n : n
44 % Vertical displacements :
45 % moves elements up , adds zeros above
46 if i < 0

36
47 Av = padarray ( Ah (1: dim (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
48 end
49

50 % moves elements down , adds zeros below


51 if i > 0
52 Av = padarray ( Ah (1+ i : dim (1) ,:) ,[ i 0] , ’ post ’) ;
53 end
54

55 % when reaching the center element - do nothing .


56 if i == 0
57 Av = Ah ;
58 end
59 % For each step , the variance is calculated for each pixel ,
60 % based on the current value , and the mean of that pixel .
61 A_sum = Av .* exp ( - Speckle_index .* a .* sqrt ( k ^2+ i ^2) ) + A_sum ;
62 weight = weight + exp ( - Speckle_index .* a .* sqrt ( k ^2+ i ^2) ) ;
63

64 end
65 end
66 clear Speckle_index Av Ah % clear up memory
67 % % Creates the new picture
68 Im = A_sum ./ weight ;
69 clear A_sum weight % clear up memory
70 % assing dead pixels
71 Im ( dim (1) -n +1: dim (1) ,:) = deadpixel ;
72 Im (1: n ,:) = deadpixel ;
73 Im (: , dim (2) -n +1: dim (2) ) = deadpixel ;
74 Im (: ,1: n ) = deadpixel ;
75 % % Return Filtered images
76 FrostImages = Im ;
77 end

6.2.4 modifiedFrost.m

1 function modFrostImages = modifiedFrost ( Im , n , a )


2 % modifiedFrost ( Im ,n , a )
3 % The modifiedFrost function filtes an image with the modified Frost filter .
4 % It works much like the frost filter , but uses the CFAR from the function
5 % CFAR in order to filter the image .
6 % input : Im = the givin image one wish to filter
7 % n = Number of pixels on each side of the center pixel . use 3 or 4.
8 % a = sensitivity
9 % output : modFrostImages = Modified Frost fitlered image .
10 % Example : modifiedFrost ( img , 4 , 5)
11 %

37
12 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
13 dim = size ( Im ) ; % dimensions of input matrix .
14 deadpixel = 0;
15 % % Local values
16 E = localMean ( Im , n ) ;
17 V = localVariance ( Im ,E , n ) ;
18 VMR = V ./ E .^2;
19 CFAR_mfrost = CFAR ( VMR ) ;
20 threshold = 1/ mean ( CFAR_mfrost ) ;
21 clear E V
22 % % Modified speckle index
23 Speckle_index = VMR -1/ threshold ; % spekle index
24 Speckle_index ( Speckle_index <0) = 0;
25 clear VMR
26 % % Frost filter code
27 A_sum = 0;
28 weight = 0;
29 for k = -n : n
30 % Horizontal displacements :
31 % moves element to the left , adds zeros on the left , if k is on the
32 % left of the center array ( - n ) .
33 if k <0
34 Ah = padarray ( Im (: , 1: dim (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
35 end
36 % moves element to the right , adds zeros on the right
37 if k >0
38 Ah = padarray ( Im (: , 1+ k : dim (2) ) ,[0 k ] , ’ post ’) ;
39 end
40 % when reaching the center element - do nothing .
41 if k == 0
42 Ah = Im ;
43 end
44 for i = -n : n
45 % Vertical displacements :
46 % moves elements up , adds zeros above
47 if i < 0
48 Av = padarray ( Ah (1: dim (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
49 end
50 % moves elements down , adds zeros below
51 if i > 0
52 Av = padarray ( Ah (1+ i : dim (1) ,:) ,[ i 0] , ’ post ’) ;
53 end
54 % when reaching the center element - do nothing .
55 if i == 0
56 Av = Ah ;

38
57 end
58 % For each step , the variance is calculated for each pixel ,
59 % based on the current value , and the mean of that pixel .
60 A_sum = Av .* exp ( - Speckle_index .* a .* sqrt ( k ^2+ i ^2) ) + A_sum ;
61 weight = weight + exp ( - Speckle_index .* a .* sqrt ( k ^2+ i ^2) ) ;
62 end
63 end
64 clear Speckle_index Av Ah % clear up memory
65 % % Creates the new picture
66 Im = A_sum ./ weight ;
67 clear A_sum weight % clear up memory
68 % assing dead pixels
69 Im ( dim (1) -n +1: dim (1) ,:) = deadpixel ;
70 Im (1: n ,:) = deadpixel ;
71 Im (: , dim (2) -n +1: dim (2) ) = deadpixel ;
72 Im (: ,1: n ) = deadpixel ;
73 % Return Filtered images
74 modFrostImages = Im ;
75 end

6.2.5 LeeFilter.m

1 function LeeImages = LeeFilter ( Im , n , ENL , functionMode )


2 % LeeFilter .
3 % The LeeFilter function filtes an image with the Lee filter .
4 %
5 % input : Im = the givin image one wish to filter
6 % n = Number of pixels on each side of the center pixel . use 3 or 4.
7 % ENL = A mean value of ENL from the homogenous regions .
8 % functionmode = How on wish to filter , use ’r ’ for ratio or ’d ’ for
9 % difference .
10 %
11 % output : LeeImages = Lee fitlered image .
12 %
13 % Example : LeeFilter ( img , 4 , 4.5 , ’r ’)
14 % takes the image img , uses a 9 x9 kernel and a ENL of 4.5 to
15 % ratio filter the image . Giving a filted image .
16 %
17 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
18 %
19 %%
20 % functionMode can be ’d ’ for difference or ’r ’ for ratio
21 %%
22 % threshold between 0 and 1
23 dim = size ( Im ) ; % dimensions of input matrix .

39
24 deadpixel = 0;
25 sigma_v = sqrt (1/ ENL ) ;
26 % % Local values with out mask
27 E_norm = localMean ( Im , n ) ;
28 Var_y_norm = localVariance ( Im , E_norm , n ) ;
29 Var_x_norm = ( Var_y_norm - E_norm .^2* sigma_v ^2) ./(1+ sigma_v ^2) ;
30 k_norm = Var_x_norm ./ Var_y_norm ;
31 k_norm ( k_norm <0) =0;
32 CFAR_lee = CFAR ( k_norm ) ;
33 threshold = mean ( CFAR_lee ) ;
34 % % Local values with mask
35 Mask = maskDetect ( Im , n , functionMode ) ;
36 Mask ( k_norm < threshold ) = -1; % sets k value under threshold to have no mask %
visualiser masker efter dette
37 E = localMeanMask ( Im , n , Mask ) ;
38 Var_y = localVarianceMask ( Im ,E , n , Mask ) ;
39 % % Weight
40 Var_x = ( Var_y - E .^2* sigma_v ^2) ./(1+ sigma_v ^2) ;
41 k = Var_x ./ Var_y ;
42 k (k <0) =0;
43 % % Creates the new picture
44 Im = E + k .*( Im - E ) ;
45 % assing dead pixels
46 Im ( dim (1) -n +1: dim (1) ,:) = deadpixel ;
47 Im (1: n ,:) = deadpixel ;
48 Im (: , dim (2) -n +1: dim (2) ) = deadpixel ;
49 Im (: ,1: n ) = deadpixel ;
50 % % Return Filtered images
51 LeeImages = Im ;
52 end

6.2.6 gammaEdge.m

1 function edge = gammaEdge ( Image , deadpixel )


2 % The gammaEdge function takes af image as input in order to detect
3 % itsedges . This is done with a kernel .
4 %
5 % input : Image = the givin image one wish to perform the gamme operator on
6 % deadpixel = giving the values on the edges on the original image a
7 % value
8 % output : edge = gamme operated iamge .
9 %
10 % Example : gammaEdge ( img , ’on ’) ;
11 % performs gamme on img . ’on ’ gives the operator a deadpixel value of
0.

40
12 %
13 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
14 %%
15 % Handling variable input ’ deadpixel ’. If no input , it ’ s interpreted as
16 % ’off ’ and set to zero ( since assigning to ’off ’ doesn ’ t work )
17 if nargin == 1
18 deadpixel = 0;
19 end
20

21 n =1; % size of kernel


22 dimensions = size ( Image ) ; % dimensions of input matrix .
23 edgeY = 0; % Empty array for mean values .
24 Yright = 0;
25 Yleft = 0;
26

27 edgeX = 0;
28 Xtop = 0;
29 Xbottom = 0;
30 % % Determins edges in Y - direction
31 for k = -n : n
32 % Horizontal displacements :
33 % moves element to the left , adds zeros on the left , if k is on the
34 % left of the center array ( - n ) .
35 if k <0
36 Eh = padarray ( Image (: , 1: dimensions (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
37 end
38 % moves element to the right , adds zeros on the right
39 if k >0
40 Eh = padarray ( Image (: , 1+ k : dimensions (2) ) ,[0 k ] , ’ post ’) ;
41 end
42 % when reaching the center element - do nothing .
43 if k ~= 0
44 for i = -n : n
45 % Vertical displacements :
46 % moves elements up , adds zeros above
47 if i < 0
48 Ev = padarray ( Eh (1: dimensions (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
49 end
50 % moves elements down , adds zeros below
51 if i > 0
52 Ev = padarray ( Eh (1+ i : dimensions (1) ,:) ,[ i 0] , ’ post ’) ;
53 end
54 % when reaching the center element - do nothing .
55 if i == 0
56 Ev = Eh ;

41
57 end
58 if k < 0
59 Yleft = Ev + Yleft ;
60 end
61 if k > 0
62 Yright = Ev + Yright ;
63 end
64 end
65 end
66 end
67 Yleft ( Yleft <0.01) =0.01; % The low values are set to 0.01 s we don ’ t divde
by zero or anything near .
68 Yright ( Yright <0.01) =0.01;
69 edgeY = Yleft ./ Yright ;
70 edgeY ( edgeY <1) = 1./ edgeY ( edgeY <1) ;
71 edgeY = edgeY -1; % set so noEdge =0
72 clear Yleft Yright Ev Eh
73 % % Determines edges in X - direction
74 for k = -n : n
75 % Horizontal displacements :
76 % moves element to the left , adds zeros on the left , if k is on the
77 % left of the center array ( - n ) .
78 if k <0
79 Eh = padarray ( Image (: , 1: dimensions (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
80 end
81 % moves element to the right , adds zeros on the right
82 if k >0
83 Eh = padarray ( Image (: , 1+ k : dimensions (2) ) ,[0 k ] , ’ post ’) ;
84 end
85 % when reaching the center element - do nothing .
86 if k == 0
87 Eh = Image ;
88 end
89 for i = -n : n
90 % Vertical displacements :
91 % moves elements up , adds zeros above . Then adds to top
92 % variable
93 if i < 0
94 Ev = padarray ( Eh (1: dimensions (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
95 Xtop = Ev + Xtop ;
96 end
97 % moves elements down , adds zeros below . Then adds to bottom
98 % variable
99 if i > 0
100 Ev = padarray ( Eh (1+ i : dimensions (1) ,:) ,[ i 0] , ’ post ’) ;

42
101 Xbottom = Ev + Xbottom ;
102 end
103 end
104 end
105 Xtop ( Xtop <0.01) = 0.01; % The low values are set to 0.01 s we don ’ t divde
by zero or anything near .
106 Xbottom ( Xbottom <0.01) = 0.01;
107 edgeX = Xtop ./ Xbottom ;
108 edgeX ( edgeX <1) = 1./ edgeX ( edgeX <1) ;
109 edgeX = edgeX -1; % set so noEdge =0
110 clear Xtop Xbottom Ev Eh
111 % % Finalization of edges :
112 edgetotal = sqrt (( edgeY ) .^2 + ( edgeX ) .^2) ;
113 if deadpixel == ’ on ’;
114 edgetotal ( dimensions (1) -5+1: dimensions (1) ,:) = 0;
115 edgetotal (1:5 ,:) = 0;
116 edgetotal (: , dimensions (2) -5+1: dimensions (2) ) = 0;
117 edgetotal (: ,1:5) = 0;
118 end
119 edge = edgetotal ;
120 end

6.2.7 CFAR.m

1 function threshold = CFAR ( img , procent )


2 % This function determines the constant false alarm rate ( CFAR ) threshold . Here
it is set to 1%
3 % in order to get a meaningful amount of pixel above the threshold ( the
4 % images considered are small ) . Since index are only whole numbered , the
5 % final CFA will be given as 1% + - uncertainty ( due to rounding off ) .
6 % The function sums the intensities from the homogenous regions , and uses
7 % the higest number of pixel intensities as defiend from procent .
8 %
9 % input : img = the givin image one wish to use a CFAR for .
10 % Procent = the procentage one would use .
11 %
12 % output : Threshold = CFAR threshold
13 %
14 % Example : CFAR ( img ,1)
15 % calcualtes the CFAR .
16 %
17 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
18 %
19 if nargin == 1
20 procent =1;

43
21 end
22 r1 = [10.5100 114.5100 115.9800 117.9800]; % vand
23 r2 = [359.5100 677.5100 37.9800 38.9800]; % lys mark
24 r3 = [500.5100 743.5100 67.9800 75.9800]; % m r k mark
25

26 data = [ reshape ( imcrop ( img , r1 ) , 1 ,[]) , reshape ( imcrop ( img , r2 ) , 1 ,[]) , reshape (
imcrop ( img , r3 ) , 1 ,[]) ];
27 sortedVector = sort ( data ) ;
28 len = length ( sortedVector ) ;
29 index = round ( len - len /100* procent ) ;
30 % threshold
31 threshold = sortedVector ( index ) ;
32 % creates sorted vector based on all array elements

6.2.8 localMeanMask.m

1 function E = localMeanMask ( Image , n , Mask )


2 % The following function calculates the average of a mask . This is used as
3 % input in the Lee filter . This function should always be used with the
4 % function maskDetect . m .
5 %
6 % input : Image = the givin image one wish to filter
7 % n = Number of pixels on each side of the center pixel . Only 3 and
4 are valid options
8 % Mask = gives the function a mask as computated in function
9 % maskDetect . m
10 % output : E = Mask Mean value .
11 %
12 % Example : localMeanMask ( img , 4 , Mask ) ;
13 % Calcualted the Mean for the image img with n =4 , hence no
14 % overlapping . The value Mask is calculated from the function
15 % maskDetect . m .
16 %
17 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
18 %%
19 % difine masks as in lee article
20 Mask0 = [ zeros ( n *2+1 , n ) , ones ( n *2+1 , n +1) ];
21 Mask1 = ones (2* n +1 ,2* n +1) ;
22 for r = [2:2* n +1]
23 Mask1 (r ,:) = [ zeros (1 ,r -1) , ones (1 ,2* n +2 - r ) ];
24 end
25 Mask2 = [ ones ( n +1 , n *2+1) ; zeros (n , n *2+1) ];
26 Mask3 = fliplr ( Mask1 ) ;
27 Mask4 = fliplr ( Mask0 ) ;
28 Mask5 = flipud ( Mask3 ) ;

44
29 Mask6 = flipud ( Mask2 ) ;
30 Mask7 = fliplr ( Mask5 ) ;
31 % intial values
32 dimensions = size ( Image ) ; % dimensions of input matrix .
33 E_sum = zeros ( dimensions (1) , dimensions (2) ) ; % Empty array for mean values .
34 % For each iteration the array is moved one step in the given direction . For
35 % each iteration all the current mean are calculated , and added to E_sum .
36 % Iterations works its way from left to right in the array .
37 for k = -n : n
38 % Horizontal displacements :
39 % moves element to the left , adds zeros on the left , if k is on the
40 % left of the center array ( - n ) .
41 if k <0
42 Eh = padarray ( Image (: , 1: dimensions (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
43 end
44 % moves element to the right , adds zeros on the right
45 if k >0
46 Eh = padarray ( Image (: , 1+ k : dimensions (2) ) ,[0 k ] , ’ post ’) ;
47 end
48 % when reaching the center element - do nothing .
49 if k == 0
50 Eh = Image ;
51 end
52 for i = -n : n
53 % Vertical displacements :
54 % moves elements up , adds zeros above
55 if i < 0
56 Ev = padarray ( Eh (1: dimensions (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
57 end
58 % moves elements down , adds zeros below
59 if i > 0
60 Ev = padarray ( Eh (1+ i : dimensions (1) ,:) ,[ i 0] , ’ post ’) ;
61 end
62 % when reaching the center element - do nothing .
63 if i == 0
64 Ev = Eh ;
65 end
66 x = k + n +1;
67 y = i + n +1;
68 E_sum ( Mask ==0) = Mask0 (y , x ) / sum ( sum ( Mask0 ) ) * Ev ( Mask ==0) + E_sum (
Mask ==0) ;
69 E_sum ( Mask ==1) = Mask1 (y , x ) / sum ( sum ( Mask1 ) ) * Ev ( Mask ==1) + E_sum (
Mask ==1) ;
70 E_sum ( Mask ==2) = Mask2 (y , x ) / sum ( sum ( Mask2 ) ) * Ev ( Mask ==2) + E_sum (
Mask ==2) ;

45
71 E_sum ( Mask ==3) = Mask3 (y , x ) / sum ( sum ( Mask3 ) ) * Ev ( Mask ==3) + E_sum (
Mask ==3) ;
72 E_sum ( Mask ==4) = Mask4 (y , x ) / sum ( sum ( Mask4 ) ) * Ev ( Mask ==4) + E_sum (
Mask ==4) ;
73 E_sum ( Mask ==5) = Mask5 (y , x ) / sum ( sum ( Mask5 ) ) * Ev ( Mask ==5) + E_sum (
Mask ==5) ;
74 E_sum ( Mask ==6) = Mask6 (y , x ) / sum ( sum ( Mask6 ) ) * Ev ( Mask ==6) + E_sum (
Mask ==6) ;
75 E_sum ( Mask ==7) = Mask7 (y , x ) / sum ( sum ( Mask7 ) ) * Ev ( Mask ==7) + E_sum (
Mask ==7) ;
76 % If area is under threshold
77 E_sum ( Mask == -1) = 1/(2* n +1) ^2 * Ev ( Mask == -1) + E_sum ( Mask == -1) ;
78 end
79 end
80 E = E_sum ;
81 end

6.2.9 localVarianceMask.m

1 function V = localVarianceMask ( Im , localMeanMask , n , Mask )


2 % The following function calculates the variance of a mask . This is used as
3 % input in the Lee filter . This function should always be used with the
4 % functions localMeanMask . m and maskDetect . m
5 %
6 % input : Image = the givin image one wish to filter
7 % localMeanMask = Input from function .
8 % Mask = gives the function a mask as computated in function
9 % maskDetect . m
10 % output : n = number of pixels on each side . use only 3 or 4.
11 %
12 % Example : localMeanMask ( img , 4 , Mask ) ;
13 % Calcualted the Mean for the image img with n =4 , hence no
14 % overlapping . The value Mask is calculated from the function
15 % maskDetect . m .
16 %
17 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
18 %%
19 % The variance will be given locally for each pixel in a matrix of dimensions
20 % " dim " based on the input image .
21 % difine masks as in lee article
22 Mask0 = [ zeros ( n *2+1 , n ) , ones ( n *2+1 , n +1) ];
23 Mask1 = ones (2* n +1 ,2* n +1) ;
24 for r = [2:2* n +1]
25 Mask1 (r ,:) = [ zeros (1 ,r -1) , ones (1 ,2* n +2 - r ) ];
26 end

46
27 Mask2 = [ ones ( n +1 , n *2+1) ; zeros (n , n *2+1) ];
28 Mask3 = fliplr ( Mask1 ) ;
29 Mask4 = fliplr ( Mask0 ) ;
30 Mask5 = flipud ( Mask3 ) ;
31 Mask6 = flipud ( Mask2 ) ;
32 Mask7 = fliplr ( Mask5 ) ;
33 % intial values
34 dim = size ( Im ) ; % dimensions of input matrix .
35 V_sum = zeros ( dim (1) , dim (2) ) ; % Empty array for mean values .
36 for k = -n : n
37 % Horizontal displacements :
38 % moves element to the left , adds zeros on the left , if k is on the
39 % left of the center array ( - n ) .
40 if k <0
41 Vh = padarray ( Im (: , 1: dim (2) - abs ( k ) ) ,[0 abs ( k ) ] , ’ pre ’) ;
42 end
43 % moves element to the right , adds zeros on the right
44 if k >0
45 Vh = padarray ( Im (: , 1+ k : dim (2) ) ,[0 k ] , ’ post ’) ;
46 end
47 % when reaching the center element - do nothing .
48 if k == 0
49 Vh = Im ;
50 end
51 for i = -n : n
52 % Vertical displacements :
53 % moves elements up , adds zeros above
54 if i < 0
55 Vv = padarray ( Vh (1: dim (1) - abs ( i ) ,:) ,[ abs ( i ) 0] , ’ pre ’) ;
56 end
57 % moves elements down , adds zeros below
58 if i > 0
59 Vv = padarray ( Vh (1+ i : dim (1) ,:) ,[ i 0] , ’ post ’) ;
60 end
61 % when reaching the center element - do nothing .
62 if i == 0
63 Vv = Vh ;
64 end
65 % For each step , the variance is calculated for each pixel ,
66 % based on the current value , and the mean of that pixel .
67 x = k + n +1;
68 y = i + n +1;
69 V_sum ( Mask ==0) = Mask0 (y , x ) / sum ( sum ( Mask0 ) ) *( Vv ( Mask ==0) -
localMeanMask ( Mask ==0) ) .^2 + V_sum ( Mask ==0) ;

47
70 V_sum ( Mask ==1) = Mask1 (y , x ) / sum ( sum ( Mask1 ) ) *( Vv ( Mask ==1) -
localMeanMask ( Mask ==1) ) .^2 + V_sum ( Mask ==1) ;
71 V_sum ( Mask ==2) = Mask2 (y , x ) / sum ( sum ( Mask2 ) ) *( Vv ( Mask ==2) -
localMeanMask ( Mask ==2) ) .^2 + V_sum ( Mask ==2) ;
72 V_sum ( Mask ==3) = Mask3 (y , x ) / sum ( sum ( Mask3 ) ) *( Vv ( Mask ==3) -
localMeanMask ( Mask ==3) ) .^2 + V_sum ( Mask ==3) ;
73 V_sum ( Mask ==4) = Mask4 (y , x ) / sum ( sum ( Mask4 ) ) *( Vv ( Mask ==4) -
localMeanMask ( Mask ==4) ) .^2 + V_sum ( Mask ==4) ;
74 V_sum ( Mask ==5) = Mask5 (y , x ) / sum ( sum ( Mask5 ) ) *( Vv ( Mask ==5) -
localMeanMask ( Mask ==5) ) .^2 + V_sum ( Mask ==5) ;
75 V_sum ( Mask ==6) = Mask6 (y , x ) / sum ( sum ( Mask6 ) ) *( Vv ( Mask ==6) -
localMeanMask ( Mask ==6) ) .^2 + V_sum ( Mask ==6) ;
76 V_sum ( Mask ==7) = Mask7 (y , x ) / sum ( sum ( Mask7 ) ) *( Vv ( Mask ==7) -
localMeanMask ( Mask ==7) ) .^2 + V_sum ( Mask ==7) ;
77 % If area is under threshold
78 V_sum ( Mask == -1) = 1/(2* n +1) ^2 *( Vv ( Mask == -1) - localMeanMask ( Mask
== -1) ) .^2 + V_sum ( Mask == -1) ;
79 end
80 end
81 V = V_sum ;

6.2.10 Colorshow.m

1 function ColorIm = Colorshow ( Im , levels )


2 % The following function is used for displaying the different levels in
3 % intensities for our images .
4 %
5 % input : Im = the givin image one wish to filter
6 % Levels = The different thresholds for asigning areas different colors .
7 %
8 % output : ColorIm = Im with colurs .
9 %
10 % Example : Colorshow ( frost_img , [0 0.04 0.1 0.2 0.3 0.6 0.7] )
11 % this taget the image frost_img and assigns a colour for 0 -0.04.
12 % Another color for 0.04 -0.1 ect .
13 %
14 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
15 %
16 % % colors
17 b =[0 0 1]; g =[0 1 0]; m =[0 1 1]; c =[1 0 1]; y =[1 1 0]; w =[1 1 1]; r =[1 0 0]; k
=[0 ,0 ,0]; dg =[0 0.4 0]; % different color definitions
18 %
19 colors = [ g ; r ; c ; m ; b ; w ; y ; dg ];
20 %%
21 dim = size ( Im ) ;

48
22 zeroColor = k ;
23 red = zeroColor (1) * ones ( dim (1) , dim (2) ) ;
24 green = zeroColor (2) * ones ( dim (1) , dim (2) ) ;
25 blue = zeroColor (3) * ones ( dim (1) , dim (2) ) ;
26 for i =1: length ( levels )
27 levelColor = colors (i ,:) ;
28 threshold = levels ( i ) ;
29 red ( Im > threshold ) = levelColor (1) ;
30 green ( Im > threshold ) = levelColor (2) ;
31 blue ( Im > threshold ) = levelColor (3) ;
32 end
33

34 Im = cat (3 , red , green , blue ) ;


35 clear red green blue
36 ColorIm = Im ;
37 end

6.2.11 evalTestImage.m

1 function [ mean_Array , variance_Array , inv_VMR_Array , edgeIntensity ] =


evalTestImage ( TestImage )
2 % This function calculates different values for the different areas in the
3 % picture in order to compare values in the differendt images .
4 %
5 %
6 % input : TestImage = the givin image one wish to evaluate , Both original
7 % and filtered imaged .
8 %
9 % output : Four different arrays .
10 % mean_Array = mean value of region
11 % variance_Array = varians of a region
12 % inv_VMR_Array = 1/ VMR of a region , for homogenous = ENL
13 % edgeIntensity = intensities of edges , used for evaluating
14 % edges
15 %
16 % Example : evalTestImage ( frost ) ;
17 % evaluate a image called frost .
18 %
19 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
20 %
21 mean_Array = zeros (1 ,6) ;
22 variance_Array = zeros (1 ,6) ;
23 inv_VMR_Array = zeros (1 ,6) ;
24 r1 = [10.5100 114.5100 115.9800 117.9800]; % vand
25 r2 = [359.5100 677.5100 37.9800 38.9800]; % lys mark

49
26 r3 = [500.5100 743.5100 67.9800 75.9800]; % m r k mark
27 r4 = [309.5100 13.5100 86.9800 87.9800]; % kyst linje
28 r5 = [245.5100 416.5100 78.9800 71.9800]; % mark s k l
29 r6 = [703.5100 101.5100 105.9800 90.9800]; % narkskov ( urban )
30 r = [ r1 ; r2 ; r3 ; r4 ; r5 ; r6 ];
31 for i = 1:6
32 img = imcrop ( TestImage , r (i ,:) ) ;
33 data = reshape ( img ,1 ,[]) ;
34 mean_Array ( i ) = mean ( data ) ;
35 variance_Array ( i ) = var ( data ) ;
36 inv_VMR_Array ( i ) = mean_Array ( i ) ^2/ variance_Array ( i ) ;
37

38 end
39 % % Edges
40 % Image filtering :
41 edge = gammaEdge ( TestImage , ’ on ’) ;
42

43 % Parameter value
44 % Removes everything below CFAR threshold
45

46 thresholdEdge = CFAR ( edge ) ;


47 edge ( edge < mean ( thresholdEdge ) ) = 0;
48

49 % Sums all pixel intensities in the filtered image , and removes intensities
50 % from the city .
51 edgeNumber = edge ;
52 edgeNumber ( edge >0) =1;
53 %
54 edgeNumberUhom = sum ( sum ( imcrop ( edgeNumber , r4 ) ) ) + sum ( sum ( imcrop (
edgeNumber , r5 ) ) ) ;
55 edgeNumberHom = sum ( sum ( imcrop ( edgeNumber , r1 ) ) ) + sum ( sum ( imcrop ( edgeNumber
, r2 ) ) ) + sum ( sum ( imcrop ( edgeNumber , r3 ) ) ) ;
56 edgevalueUhom = sum ( sum ( imcrop ( edge , r4 ) ) ) + sum ( sum ( imcrop ( edge , r5 ) ) ) ;
57 edgevalueHom = sum ( sum ( imcrop ( edge , r1 ) ) ) + sum ( sum ( imcrop ( edge , r2 ) ) ) + sum (
sum ( imcrop ( edge , r3 ) ) ) ;
58

59

60 edgeIntensity = [ edgevalueUhom ./ edgeNumberUhom ; edgevalueHom ./


edgeNumberHom ];
61 end

6.2.12 loadTestImage.m

1 function img = loadTestImage ( path )


2 % This function is desined for loading our image in matlab .

50
3 % Here , de different information is found in the . hdr file from our origial
4 % image from sentinalHub .
5 %
6 % authors : Eigil Lippert , Kristian S r e n s e n and Simon Lupemba
7

8 %% Binary file input


9 filNavn = path ;
10 % ’r ’ is read , ‘w ‘ is write ect ..
11 filID = fopen ( filNavn , ’r ’) ;
12 %% Load the picture
13 % This info is found in the giving . hdr header .
14 precision = ’ float32 ’;
15 dim = [ 11137 6787];
16 img = fread ( filID , dim , precision , ’b ’) ;
17 dim1 = [6787 11137 ];
18 img1 = imrotate ( img ,90) ;
19

20 % Croping the original picture and saving it as a new one .


21 koor = 1.0 e +03 *[0.80 2.3 0.900 0.900];
22 img = imcrop ( img1 , koor ) ;
23 end

51

You might also like