### Filter

The concept of filtering involves neighborhood operations work with the values of the image pixels in the neighborhood and the corresponding values of a sub image that has the same dimensions as the neighborhood. The Filter operation can be classified as:

#### Edge Filter

Local discontinuities in image luminance from one level to another are called luminance edges, limited to image amplitude discontinuities between reasonably smooth regions. There are two major classes of differential edge detection: first- and second-order derivative. For the first-order class, some form of spatial first-order differentiation is performed, and the resulting edge gradient is compared to a threshold value. An edge is judged present if the gradient exceeds the threshold. For the second-order derivative class of differential edge detection, an edge is judged present if there is a significant spatial change in the polarity of the second derivative.

- Sobel: The Sobel operator edge detector where the mask values of the north, south, east, and west pixels are doubled. The motivation for this weighting is to give equal importance to each pixel in terms of its contribution to the spatial gradient.

- Roberts: Diagonal edge gradients can be obtained by forming running differences of diagonal pairs of pixels. This is the basis of the Roberts cross-difference operator:

#### Smoothing Spatial Filters

Smoothing filters are used for blurring and for noise reduction. Blurring is used in preprocessing steps, such as removal of small details from an image prior to (large) object extraction, and bridging of small gaps in lines or curves. Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear filtering.

- Mean: The output of a mean, linear spatial filter is simply the average of the pixels contained in the neighborhood of the filter mask. These filters sometimes are called averaging filters or lowpass filters. A major use of averaging filters is in the reduction of “irrelevant” detail in an image. By “irrelevant” we mean pixel regions that are small with respect to the size of the filter mask.

- Mode: The Mode filter is used to remove noise from an image by replacing pixels with the most frequently occurring pixel value selected from a certain window size.

- Median: A median filter, which, as its name implies, replaces the value of a pixel by the median of the gray levels in the neighborhood of that pixel (the original value of the pixel is included in the computation of the median). Median filters are quite popular because, for certain types of random noise, they provide excellent noise-reduction capabilities, with considerably less blurring than linear smoothing filters of similar size.

#### Morphological Filters

Morphological image processing is a type of processing in which the spatial form or structure of objects within an image are modified. Dilation and erosion are three fundamental morphological operations.

- Dilation: With dilation, an object grows uniformly in spatial extent, whereas with erosion an object shrinks uniformly.

- Erosion: With erosion an object shrinks uniformly.

It is accessible through:
Raster Processing > Filter... (list of all raster layers will be available)
This wizard consists of the following steps:

#### Wizard Page 1 - Selection of the layer to apply the filter (Layer Search)

1. On the List of Layers select the raster layer to apply the filter.
2. Optionally use Filter By Name field giving part of the layer name to help find the layer in the list.
3. Press Next to go to next step or Cancel to close the dialog.

#### Wizard Page 2 - Filter parameters

1. Select the Type of filter to be used.
2. Set the number of iterations.
3. In Bands select the desired bands to be processed.
4. On the Preview section click on to have a preview of the filter with the parameters informed.
5. Press Next to apply the contrast or Back to go to the previous wizard page.

If the user selects the "User Defined" type, is allowed to define information about the mask being used.

- Size: size of the mask
- Default Value: default value used in the mask.
- The tool shows a empty component that allows the definition of a mask with a size defined by the user.
- The tool shows a component with previous mask defined by the user.

#### Wizard Page 3 - Output information

1. Raster Info - First press and inform the folder where the resulting file will be saved.
2. Name - inform the raster name.
3. Extra Parameters - if there are some, see the details on how to inform then here.
4. Press Finish to save the resulting contrasted raster or Back to go to the previous wizard page.

Hint: The filtered image will be added as a new layer at the TerraView project.