Fortunately airship combat individual + group [6139371] precision landing, worry-free return of blood

Fortunately airship combat individual + group [6139371] precision landing, worry-free return of blood

Q technical expert group 6,139,371 online manual one guidance throughout the day! Years of experience and knowledge to share! Win team teach you practical plans!

Median filter (Median Filter) is a non-linear filtering technique, the basic idea is to sort the pixel gradation value in the neighborhood of a single channel, the intermediate value to replace the original pixel gray value. Median filtering is currently the best way to process the filtering salt and pepper noise.
Pepper noise (salt-and-pepper noise), also known as impulse noise, or remote sensor during transmission, the original data will be affected, causing a lot of noise points scattered images appear granular. In the image, most of the energy concentrated in low and medium frequencies, so the intermediate value data sorting neighborhood rarely taken to get the high-frequency contamination point.

First, a few basic concepts
(1) What is the linear filtering and nonlinear filtering?

Linear Filtering:
refers to two or more signals and a sum equal to their respective response and the response. So too academic, and is simply the output value of each pixel of the image is equal to the weighted number of input pixels and.

Nonlinear Filtering:
included in the calculation of the absolute value, like the nonlinear operation zero.
. 1
2
. 3
. 4
. 5
. 6
(2) neighboring pixel points
as the name implies, a pixel refers to the number of neighborhood pixels adjacent to the pixel.


Second, the principle of the median filter
if it is not an edge region, the image data is gentle, there is not much difference. Therefore, the value of a noise point is either too large or too small. FIG picture such as the following, is left untreated, the region 250 protrudes through 9 by the data sorting 3 * 3, the intermediate value of 150 refilled, i.e. the filter is completed, the original point is the noise It is removed, the recovery zone flat. Similarly, in the edge region, the boundary, it will not affect the high-frequency, and low value will protrude, the selection value will not be affected, unless the entire region of the 3 * 3 is polluted, which we could consider a larger core to deal with.


Third, the median filtering process implemented
first look at the effect of the program:

(1) main functions: reading image - median filter - Display

main int (void)
{
// [. 1] Image reading the src
CV = CV :: :: Mat imread the src ( "pic3.jpg");
// [2] DST target picture
CV :: Mat DST;
// [ 3] median filter RGB (5 * 5) the nuclear size
dealMedianRGB (the src, DST,. 5,. 5);
// [. 4] form is shown
CV :: imshow ( "the src", the src);
CV :: imshow ( "DST", DST);
CV :: waitKey (0);
CV :: destroyAllWindows ();
return 0;
}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
channel separation (2) a color image
in median filtering operation on values of pixel points on a channel, thus, a color image is to be separated (the RGB), respectively, for the R channel, G-channel, B channel median filter, and finally combined.

dealMedianGary void (* const the src Mat :: CV, CV :: * Mat DST, n-int, int m)
{
// [. 1] Initialization
* DST = (the src *) .clone ();
// [2] Color Image channel separation
STD :: Vector <CV :: Mat> channels;
CV :: Split (the src *, channels);
// [. 3] filtering
for (int I = 0; I <. 3; I ++) {
MedianGary (& channels [I ], n-, m);
}
// [. 4] combined return
CV :: merge (channels, * DST);
return;
}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
(. 3) median filter the main routine, by each pixel of the scanned image, and then determines a rectangular area according to a 5x5 pixel, the data obtained in the sorting area a return value, the final value of the output pixel is filled.
The code can only be done 5 * 5 processing, lazy bloggers do not write the classification process, and are interested to write their own, ha ha ha ha ~

void MedianGary(cv::Mat *dst, int n, int m)
{
unsigned char *_medianArray = NULL;

// [2] 初始化
_medianArray = (unsigned char *)malloc(sizeof(unsigned char)*(n*m));

printf(" 5 * 5 start ... ... \n");
// [2-1] 扫描
for (int i = 0; i < dst->height; i++) {
for (int j = 0; j < dst->width; j++) {
// [2-2] 忽略边缘
if ((i>1) && (j>1) && (i<dst->height-2)
&& (j<dst->width-2))
{
// [2-3] 保存数组
int _count = 2;
for (int num=0; num<(n*m); num+=5,_count--)
{
_medianArray[num] = *((unsigned char*)(dst->imageData+(i-_count)*dst->widthStep+(j-2)));
_medianArray[num+1] = *((unsigned char*)(dst->imageData+(i-_count)*dst->widthStep+(j-1)));
_medianArray[num+2] = *((unsigned char*)(dst->imageData+(i-_count)*dst->widthStep+(j)));
_medianArray[num+3] = *((unsigned char*)(dst->imageData+(i-_count)*dst->widthStep+(j+1)));
_medianArray [NUM +. 4] = * ((unsigned char *) (dst-> the imageData + (I-The _count) * dst-> widthStep + (J + 2)));
}
// [2-5] and stores the value in seeking
* ((unsigned char *) (dst-> + I * dst- the imageData> widthStep + J)) = medianValue (_medianArray, (n-m *));
} // for [2-2]
}
} // for [ 2-1]
}
. 1
2
. 3
4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
18 is
. 19
20 is
21 is
22 is
23 is
24
25
26 is
27
28
29
30
31 is
(4) matrix, bubble sort used here, of course, you can also use fast discharge or other

// [## seeking median bubble ##]
unsigned char medianValue (_medianArray unsigned char *, int COUNT)
{
unsigned char TEMP;
int I, J;

// bubbling
for (J = 0; J <COUNT -. 1; J ++) {
for (I = 0; I <COUNT -. 1 - J; I ++)
{
IF (_medianArray [I]> _medianArray [I +. 1])
{
TEMP = _medianArray [I];
_medianArray [I] = _medianArray [I +. 1];
_medianArray [I +. 1] = TEMP;
}
}
}
return _medianArray [COUNT / 2];
}
--------- -------
Disclaimer: this article is CSDN blogger "Qingcheng mountain monk" of the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_36359022/article/details/80116137

Guess you like

Origin www.cnblogs.com/qun115991/p/11710316.html