Comparison of three smoothing filters (mean, median and edge of directional characteristics)

xiaoxiao2021-03-06  36

Comparison of three smoothing filters (mean, median and edge of directional characteristics)

In the acquired raw image, there are some noise, in order to eliminate these noises, some smoothing filters can be applied to the image, but the smoothing filter is often easily image blur. The smooth effect of three common smoothing filters is compared. .

Time filtering

The principle is that the sub-image in the n * n sub-block, and the gradation of the detected point is the average value of the gradation in the block, and this method achieves a smooth effect by dispersing the grayscale of the mutant point in its adjacent point. It is also simple to operate, but such smoothing tends to cause the image of the image, the N-choice is about a large, the more serious blur.

f (x, y) = 1 / (n * n)

2. Medium value filtering

Medium-value filtering is also operated in the N * N sub-block in the image, and the mean smoothing selection is different from the point average gradation value, and the median smoothing uses the intermediate grayscale is detected. Click grayscale, namely

f (x, y) = MID {f (1, 1), f (1, 2) ... f (n, n)} n ∈ [1, n]

3. Keep filtering of the edge of the track detection

This filtering method is a lot, one of which is 5 direction templates

Statistical variance D and mean E of each template

definition

Select the min smallest template to compare with the variance D of the square template, select a smaller template as the template used by the pixel, and the gradation of the other target pixel is the mean of the selected template grayscale.

This template with directional characteristics can store the edge of the image, so that the edge of the image line is not blurred because it is smooth. But the amount of calculation is relatively large.

Take a look at the three smooth results

----------------------------------------------

It can be seen that the three images become smoothed, but the average filtering fuzzy effect is very serious, the median filtering puts a relatively fine line filter, and the edge keeps filtering the edge holding the edge to maintain the edge holding, and select it as needed.

Below is my 4 smoothed C code

// ---------------------- compiled in VC.NET.

/ *

Author: lingch (sboom)

Date: 2005-1-26

Subject: Smooth Filter

* /

Bool Filterav (unsigned char * image, int hotht, int width) // mean filter

{

INT I, J;

Unsigned char * p = (unsigned char *) Malloc (Height * Width);

For (i = 1; i

{

For (j = 1; j

{

P [i * width j] = (unsigned char) ((int) image [(i-1) * width j-1]

(int) image [(i-1) * width j]

(int) image [(i-1) * Width J 1]

(int) image [i * width j-1]

(int) image [i * width j]

(int) image [i * width J 1]

(int) image [(i 1) * Width J-1]

(int) image [(i 1) * width j]

(int) image [(i 1) * Width J 1]) / 9);

}

}

For (i = 1; i

{

For (j = 1; j

{

Image [i * width j] = p [i * width j];

}

}

Free (p);

Return True;

}

// -------------------------- Medium-value filter

Bool Filtermid (unsigned char * image, int hotht, int width)

{

INT I, J, K, L;

INT POS;

UNSIGNED CHAR TEMP;

Unsigned char psr [9]; unsigned char * p = (unsigned char *) malloc (height * width);

For (i = 1; i

{

For (j = 1; j

{// --- 3 * 3 Window matrix

PSR [0] = image [(i-1) * Width J-1];

PSR [1] = image [(i-1) * width j];

PSR [2] = image [(i-1) * Width J 1];

PSR [3] = Image [i * width j-1];

PSR [4] = Image [i * width j];

PSR [5] = image [i * width j 1];

PSR [6] = image [(i 1) * Width J-1];

PSR [7] = image [(i 1) * width j];

PSR [8] = image [(i 1) * Width J 1];

// -------- Select sort

FOR (k = 0; k <9; k )

{

POS = K;

FOR (L = K; L <9; L )

{

IF (PSR [L]

POS = L;

}

Temp = psr [k];

PSR [K] = PSR [POS];

PSR [POS] = TEMP;

}

// ------ Take the value

P [i * width j] = psr [4];

}

}

For (i = 1; i

{

For (j = 1; j

{

Image [i * width j] = p [i * width j];

}

}

Free (p);

Return True;

}

/ / --------------- edge retention filter

Bool Filter5 (unsigned char * image, int hotht, int width)

{

INT I, J, K, L;

Double AV [5], AV2 [5];

Double S;

Double SD [4];

Unsigned char * p = (unsigned char *) Malloc (Height * Width);

For (i = 2; i

{

For (j = 2; j

{

AV [0] = 0.0; AV [1] = 0.0; av [2] = 0.0; av [3] = 0.0; av [4] = 0.0;

AV2 [0] = 0.0; AV2 [1] = 0.0; av2 [2] = 0.0; av2 [3] = 0.0; av2 [4] = 0.0;

AV [0] =

Image [i * width J-1]

Image [i * width j]

Image [i * width J 1]

) / 3;

AV2 [0] =

Image [i * width j-1] * image [i * width J-1]

Image [i * width j] * image [i * width j]

Image [i * width J 1] * image [i * width J 1]

) / 3-AV [0] * AV [0];

AV [1] =

Image [(i 1) * Width J-1] Image [i * width j]

Image [(i-1) * Width J 1]

) / 3;

AV2 [1] =

Image [(i 1) * Width J-1] * Image [(i 1) * width J-1]

Image [i * width j] * image [i * width j]

Image [(i-1) * Width J 1] * Image [(i-1) * Width J 1]

) / 3-AV [1] * av [1];

AV [2] =

Image [(i-1) * Width J]

Image [i * width j]

Image [(i 1) * Width J]

) / 3;

AV2 [2] =

Image [(i-1) * Width J] * Image [(i-1) * Width J]

Image [i * width j] * image [i * width j]

Image [(i 1) * width j] * image [(i 1) * width j]

) / 3-AV [2] * av [2];

AV [3] =

Image [(i-1) * Width J-1]

Image [i * width j]

Image [(i 1) * Width J 1]

) / 3;

AV2 [3] =

Image [(i-1) * Width J-1] * Image [(i-1) * Width J-1]

Image [i * width j] * image [i * width j]

Image [(i 1) * Width J 1] * Image [(i 1) * Width J 1]

) / 3-AV [3] * AV [3];

AV [4] = 0.0; av2 [4] = 0.0;

For (k = i-1; k <= i 1; k )

{

For (l = j-1; l <= j 1; l )

{

AV [4] = image [k * width l];

AV2 [4] = image [k * width l] * image [k * width l];

}

}

AV [4] = AV [4] /9.0;

AV2 [4] = AV2 [4] /9.0-AV [4] * AV [4];

For (k = 0; k <4; k )

SD [K] = AV2 [K] / AV2 [(K 2)% 4];

L = 0;

For (k = 0; k <4; k )

IF (SD [K]

L = K;

IF (AV2 [L]

P [i * width j] = av [l];

Else

P [i * width j] = av [4];

}

}

For (i = 0; i

For (j = 0; j

Image [i * width j] = p [i * width j];

Free (p);

Return True;

}

转载请注明原文地址:https://www.9cbs.com/read-63977.html

New Post(0)