Home Content «SigmaFilter GaussFilter»

Copyright: V. Miszalok
Last Modified:
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:
The addition of a percentage of the original is equivalent to an elevated weight of the central pixel[y,x] among its neighbors.
Samples:
old[y,x] a weight of 8, what means,
that old[y,x] has as many votes as its 8 neighbors togetherold[y,x] a weight of 1000, what means,
that there is no fog at all.old[y,x] a weight of 1, what means,
that old[y,x] has the same vote as any of its 8 neighborsFogFilter://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 ); ******************************************************************************************************
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];
}