• ## Basics of the Fog Filter

Fog is less aggressive variant of the average filter, which blurs heavily.
At first it executes fast averaging as a normal fast average filter does.
In an additional second path it mixes the original image with the averaged image.
Thus the central pixel obtains a higher vote than any of its 8 neighbors.
Here is the pseudo-code for a gray value pixel:

1. Take the pixel's gray value and add the gray values of its eight neighbors.
2. Divide the sum by 9, round the result to integer.
3. Write it to an intermediary image.
4. The output image is composed of a certain FilterWeight-percentage of the intermediary image plus a certain OriginalWeight-percentage of the input image.

The addition of a percentage of the original is equivalent to an elevated weight of the central `pixel[y,x]` among its neighbors.
Samples:

1. The 3x3 fog filter which gives `old[y,x]` a weight of `8`, what means, that `old[y,x]` has as many votes as its 8 neighbors together
→ This is equivalent to 50% original + 50% average filter = 50% fog.
2. The 3x3 fog filter which gives `old[y,x]` a weight of `1000`, what means, that there is no fog at all.
3. The 3x3 fog filter which gives `old[y,x]` a weight of `1`, what means, that `old[y,x]` has the same vote as any of its 8 neighbors
→ This is equivalent to a 100% average filter = 100% fog.

# Experiment:

1. Draw a thin line.
2. Drag the mixture slider and release it somewhere between 100% filter and 100% original.

# C#-Code of the `FogFilter`:

```//C#-Code of the FogFilter:
Byte[,] image0 = new Byte[ySize,xSize]; // global input image
Byte[,] image1 = new Byte[ySize,xSize]; // contains the result of the AverageFilter3x3
Byte[,] image2 = new Byte[ySize,xSize]; // global output image
double FilterWeight   = AverageFilterPrevalenceInPercent / 100.0;
double OriginalWeight = 1.0 - FilterWeight;
for ( int y=1; y < ySize-1; y++ )
for ( int x=1; x < xSize-1; x++ )
image2[y,x] = Convert.ToByte( image1[y,x]*FilterWeight +
image0[y,x]*OriginalWeight );
DrawImage( image2 );  ```

# Experiments:

1. Drag the mixture slider between 100% original and 0% original.
2. Drag the mixture slider to 100% and notice that the FWidth- and FHeight-sliders don't change anything.
3. Drag both the FWidth- and FHeight-sliders to 1 and notice that the mixture slider doesn't change anything.
4. A mystic atmosphere is obtained with a big kernel and a low original.
5. Try out with other images.

******************************************************************************************************
Q: What is a Fog Filter ? Benefit ?
A: A normal average filter with an additional feature: `pixel[y,x]` counts more than any of its neighbors.
It softens and fine tunes the brutal averaging filter.
******************************************************************************************************
Q: What means "Fog" ?
A: Fog filters mimic the effect of natural fog, creating a soft glow and flare.
They produce a warm romantic tone or a mystic atmosphere.
******************************************************************************************************
Q: Pseudo code of 3x3 fog filtering of an `image0` (=original) to `image1` (=intermediary) to `image2` (=output)
where `FilterWeight` plus `OriginalWeight` sum up to `1.0` ?

```A: for any row y
for any column x
{ for any yy=-1 to yy=1
for any xx=-1 to xx=1
sum += image0[y+yy,x+xx];
image1[y,x] = sum / 9;
image2[y,x] = FilterWeight*image1[y,x] + OriginalWeight*image0[y,x];
}```

******************************************************************************************************
Q: Pseudo code of 21x21 fog filtering of an `image0` (=original) to `image1` (=intermediary) to `image2` (=output)
where `FilterWeight` plus `OriginalWeight` sum up to `1.0` ?

```A: for any row y
for any column x
{ for any yy=-10 to yy=10
for any xx=-10 to xx=10
sum += image0[y+yy,x+xx];
image1[y,x] = sum / (21*21);
image2[y,x] = FilterWeight*image1[y,x] + OriginalWeight*image0[y,x];
}```