Image filtering method
By creating circular and semicircular masks in different directions in image processing, and combining bilateral filtering cores and Gaussian filtering cores for multiple convolutional filtering, it is solved that it is difficult to directly filter and remove in image processing in the prior art. The problem of noise achieves efficient image filtering effect.
Patent Information
- Application Number
- CN202411480969.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-11
AI Technical Summary
The prior art is difficult to directly filter in image processing, has low efficiency, and cannot effectively remove noise in the image.
Multiple convolution filtering processes are performed by creating circular and semicircular masks in different directions, combining bilateral filtering cores and Gaussian filtering cores to remove noise in the image.
It realizes efficient removal of noise in the image and filters directly, which is efficient and can effectively protect the shape, size and specific geometric and topological characteristics of the image target.
Smart Images

Figure CN119417703A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image preprocessing, and in particular to an image filtering method. Background Art
[0002] Image filtering, that is, suppressing the noise of the target image while preserving the image details as much as possible, is an indispensable operation in image preprocessing. The quality of its processing will directly affect the effectiveness and reliability of subsequent image processing and analysis. For digital image signals, the noise table is a large or small extreme value. These extreme values act on the real grayscale value of the image pixels through addition and subtraction, causing interference of bright and dark spots in the image, greatly reducing the image quality, and affecting the subsequent work such as image restoration, segmentation, feature extraction, and image recognition.
[0003] Existing window box filters mostly use rectangular masks, which have the problem of missing image information or less image retention; in addition, the Chinese invention patent publication number CN 113746451A "A filtering operation method for a circular filter" proposes a circular filtering method, which can eliminate large-scale pulse interference, making the signal data smoother, and has low cost and simple implementation process, but it needs to further obtain and count the signal value of the image when processing the image, and is only applicable to sinusoidal signals. This method cannot directly filter during image processing and has low efficiency. Therefore, it is particularly important to develop a filtering method that can directly filter during image processing, has high efficiency, and can effectively remove noise from the target and background. Summary of the invention
[0004] The technical problem to be solved by the present invention is to overcome the above-mentioned defects of the prior art and provide an image filtering method.
[0005] The present invention is achieved through the following technical solutions:
[0006] An image filtering method comprises the following steps:
[0007] S1: Read image information: read the collected biological microscopic image, convert the three-channel color image into a single-channel grayscale image, and read the pixel information in the grayscale image;
[0008] S2: Create circular masks in different directions:
[0009] S21: normalize the image read by S1, obtain its width and height from the normalized image, and store these size information in corresponding variables;
[0010] S22: Create four d-dimensional array templates. The template size calculation formula is as follows:
[0011] d = 2·r+1,
[0012] Among them, d is the size value of the template, and r is the diameter value of the given circle;
[0013] S23: According to the four templates created, four circular masks in different directions are created clockwise respectively, and then the circular masks in the four different directions are stored in the container. The coordinate formulas of the center points of the circular masks in the four different directions are:
[0014]
[0015] Where r is the diameter of a given circle; i represents the azimuth value, which can be LU, RU, RD, or LD; n can be 0, 1, 2, or 3, respectively. in (x, y) is the coordinate position of the center point of the circle, mod means the remainder after dividing by 2;
[0016] S3: Establish different types of smoothing kernels;
[0017] S4: After performing multiple convolution filtering processes on the grayscale image in S1, the filtered image is output.
[0018] With this design, filtering can be performed directly through the created template and four circular masks in different directions, which is highly efficient and can effectively remove noise from the target and background.
[0019] As an optimization, in step S23, four new templates are added based on the four original templates, and semicircular masks in four different directions are created clockwise in sequence according to the four new templates, and then the semicircular masks in four different directions are stored in the container. The center point coordinate formula of the semicircular masks in four different directions is:
[0020]
[0021] D=d,
[0022] Among them, D is the diameter of the semicircle, d is the size of the template, j represents the orientation value, which can be L, U, R, or D respectively; n can be 0, 1, 2, or 3 respectively, and N jn (x, y) is the coordinate position of the center point of the semicircle, and mod means the remainder after dividing by 2.
[0023] With this design, full coverage is achieved through the four newly created templates and four semicircular masks in different directions, further effectively removing noise from the target and background.
[0024] As an optimization, the specific steps of establishing different types of smoothing kernels in S3 are:
[0025] S31: Create different types of intermediate kernels: bilateral filter kernel, Gaussian filter kernel, select the bilateral filter kernel for filtering and create a new bilateral smoothing kernel, or select the Gaussian filter kernel for filtering and create a new Gaussian smoothing kernel;
[0026] S32: The newly created bilateral smoothing kernel or Gaussian smoothing kernel is sequentially multiplied with the circular masks in the four different directions and the semicircular masks in the four different directions, and the final eight smoothing kernels are obtained after normalization. In this design, by multiplying the newly created smoothing kernel with the circular and semicircular masks in eight different directions, the eight smoothing kernels obtained after normalization can not only effectively remove the noise in the target and the background, but also well protect the shape, size and specific geometric and topological structure features of the image target.
[0027] As an optimization, the steps for creating the bilateral filter kernel are: bilateral filtering uses both spatial Gaussian weights and gray value similarity Gaussian weights; Mat is used to first create an all-zero matrix of d, and then the value of the bilateral filter kernel is calculated according to the following formula:
[0028]
[0029] Among them, f(k,l) is the pixel value corresponding to the center coordinate point (k,l) of the template window, (n,m) is the coordinate of other coefficients of the template window, and w(n,m,k,l) is the weight value of the coordinate of the center point of the template window and the coordinate of other coefficients;
[0030] The kernel value of each coordinate point is obtained and put into the all-zero matrix of the template size d created previously. After creation, the bilateral filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn. The new kernel value is normalized again, and the above evaluation process is encapsulated as a bilateral filter kernel value function Bilateral_kernel with a type value of BILATERAl_KERNEL.
[0031] As an optimization, the steps for creating the Gaussian filter kernel are as follows: the Gaussian kernel is mainly created by a Gaussian function, and the Gaussian function formula is as follows:
[0032]
[0033] Among them, a is a constant related to the standard deviation c, c is the standard deviation, b represents the mean, and e represents the constant value 2.71828;
[0034] According to the above formula, first create a one-dimensional double-precision matrix mask of size d by getGaussianKernel in opencv, and then create a two-dimensional matrix according to matrix transposition and matrix product operations, the created Gaussian filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn, and the new kernel value is normalized, and the above evaluation process is encapsulated as a Gaussian filter kernel value function Gaussain_kernel with a type value of GAUSSIAN_KERNEL.
[0035] As an optimization, S4 performs multiple convolution filtering processes on the grayscale image in S1 and outputs the filtered image. The specific steps are as follows:
[0036] S41: Obtaining a difference image: inputting the grayscale image in S1, performing multiple convolution filtering processes, each time using different smoothing kernels; calculating the difference between each convolution filtering result and the original image according to the convolution kernel, and obtaining multiple difference images convDiff;
[0037] S42: Obtain the optimal convolution kernel: for each pixel in the grayscale image in S1, compare its value in multiple difference images, and select the convolution kernel corresponding to the difference image minIndex with the smallest value as the optimal convolution kernel;
[0038] S43: restore the grayscale image after denoising: according to the selection result of the optimal convolution kernel, enhance the original image, replace the value of each pixel in the grayscale image with its corresponding value in the optimal convolution kernel filtering result, and add an adjustment amount based on the original pixel value to form the current pixel, repeat the above steps until the predetermined number of iterations is reached, and obtain the new image grays after filtering and enhancement processing;
[0039] S44: Outputting the filtered image: converting the new image grays after filtering and enhancement processing into a format suitable for display or storage, and outputting grayResult as the filtered image.
[0040] The beneficial effects of the present invention are:
[0041] The present invention provides an image filtering method, comprising: reading image information; creating circular masks in different directions; establishing different types of smoothing kernels; and outputting the filtered image after multiple convolution filtering processes. The present invention can directly perform filtering with high efficiency and can effectively remove noise from the target and background. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The following is a further description of an image filtering method in conjunction with the accompanying drawings:
[0043] Figure 1 A schematic diagram of the flow of an image filtering method according to an embodiment of the present invention;
[0044] Figure 2 Examples of circular masks in four directions: upper left, upper right, lower right, and lower left;
[0045] Figure 3 Examples of semicircular masks in four directions: left, top, right, and bottom;
[0046] Figure 4 This is an example diagram of circular window filtering with a Gaussian filter kernel as the kernel shape;
[0047] Figure 5 This is an example diagram of circular window filtering with a bilateral filter kernel selected as the kernel shape;
[0048] Figure 6 This is an example of a circular window filter with a kernel size of (5,5) and a kernel shape of Gaussian filtering;
[0049] Figure 7 This is an example of a circular window filter with a kernel size of (15,15) and a kernel shape of Gaussian filter;
[0050] Figure 8 This is a single-channel grayscale example image with salt and pepper noise added;
[0051] Fig. 9 This is an example of using a bilateral filter kernel to filter out salt and pepper noise using a circular window filter.
[0052] Fig.10 This is an example of a circular window filter using a Gaussian filter kernel to remove salt and pepper noise.
[0053] Fig.11 An example diagram of using the circular and semicircular mask windows of the present invention to filter an image;
[0054] Fig.12 An example of filtering an image using a rectangular masked window. DETAILED DESCRIPTION
[0055] The present application is further described in detail below in conjunction with the accompanying drawings and implementation methods. It is particularly noted that the following implementation methods are only used to illustrate the present application, but do not limit the scope of the present application. Similarly, the following implementation methods are only some implementation methods of the present application rather than all implementation methods. All other implementation methods obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0056] See also Figure 1 , Figure 1The following is a flow chart of an image filtering method according to an embodiment of the present invention; an image filtering method comprises the following steps:
[0057] Step 1: Read the image information: read the collected biological microscopic image, convert the three-channel color image into a single-channel grayscale image, and read the pixel information in the grayscale image;
[0058] Step 2: Create circular masks in different directions. The specific steps are as follows:
[0059] Normalize the image read in step 1, obtain its width and height from the normalized image, and store these size information in the corresponding variables;
[0060] Create eight d-dimensional array templates. The size of the template is calculated as follows:
[0061] d = 2·r+1,
[0062] Among them, d is the size value of the template, and r is the diameter value of the given circle;
[0063] According to the eight templates created, four circular masks in different directions and four semicircular masks in different directions are created clockwise respectively, and then stored in the container;
[0064] Take the upper left side of the template N LU0 is the starting point, followed by N RU1 , N RD2 , N LD3 , according to the following formula,
[0065]
[0066] The coordinates of the center point of the circular mask in four directions are obtained as follows:
[0067]
[0068]
[0069]
[0070]
[0071] Where r is the diameter of a given circle; i represents the azimuth value, which can be LU, RU, RD, or LD; n can be 0, 1, 2, or 3, respectively. in (x, y) is the coordinate position of the center point of the circle, mod means the remainder after dividing by 2;
[0072] Take the template on the left side N L0 is the starting point, followed by N U1 , NR2 , N D3 , according to the following formula,
[0073]
[0074] The coordinates of the center point of the semicircular mask in four directions are obtained as follows:
[0075]
[0076]
[0077]
[0078]
[0079] Among them, D is the diameter of the semicircle, d is the size of the template, j represents the orientation value, which can be L, U, R, or D respectively; n can be 0, 1, 2, or 3 respectively, and N jn (x, y) is the coordinate position of the center point of the semicircle, and mod means the remainder after dividing by 2.
[0080] Based on the above data, circular and semicircular masks in eight different directions are created and added to the mask vector:
[0081] Upper Left Kernel (LU): Creates a kernel with a radius of Circular mask of
[0082] Upper Right Kernel (RU): Creates a kernel with a radius of Circular mask of
[0083] Right lower kernel (RD): Creates a kernel with a radius of A circular mask of
[0084] Lower Left Kernel (LD): Creates a kernel with a radius of Circular mask of
[0085] The circular mask images in the above four directions are as follows: Figure 2 As shown, Figure 2 Examples of circular masks in four directions: upper left, upper right, lower right, and lower left;
[0086] Left kernel (L): Creates a kernel with a radius of Semicircular mask of
[0087] Upper Kernel (U): Creates a kernel with a radius of Semicircular mask of
[0088] Right kernel (R): Creates a kernel with a radius of Semicircular mask of
[0089] Lower Kernel (D): Creates a kernel with a radius of Semicircular mask of
[0090] The semicircular mask images in the above four directions are as follows: Figure 3 As shown, Figure 3 Examples of semicircular masks in four directions: left, top, right, and bottom;
[0091] Step 3: Establish different types of smoothing kernels. The specific steps are:
[0092] Create different types of intermediate kernels: bilateral filter kernel, Gaussian filter kernel, select the bilateral filter kernel for filtering and create a new bilateral smoothing kernel, or select the Gaussian filter kernel for filtering and create a new Gaussian smoothing kernel;
[0093] The newly created bilateral smoothing kernel or Gaussian smoothing kernel is sequentially multiplied with the circular masks in the four different directions and the semicircular masks in the four different directions, and the final eight smoothing kernels are obtained after normalization.
[0094] Specifically, the steps for creating the bilateral filter kernel are: bilateral filtering uses both spatial Gaussian weights and gray value similarity Gaussian weights; Mat is used to first create an all-zero matrix of d, and then the value of the bilateral filter kernel is calculated according to the following formula:
[0095]
[0096] Among them, f(k,l) is the pixel value corresponding to the center coordinate point (k,l) of the template window, (n,m) is the coordinate of other coefficients of the template window, and w(n,m,k,l) is the weight value of the coordinate of the center point of the template window and the coordinate of other coefficients;
[0097] The kernel value of each coordinate point is obtained and put into the all-zero matrix of the template size d created previously. After creation, the bilateral filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn. The new kernel value is normalized again, and the above evaluation process is encapsulated as a bilateral filter kernel value function Bilateral_kernel with a type value of BILATERAl_KERNEL.
[0098] Specifically, the steps for creating the Gaussian filter kernel are as follows: the Gaussian kernel is mainly created by a Gaussian function, and the Gaussian function formula is as follows:
[0099]
[0100] Where a is a constant related to the standard deviation c, c is the standard deviation, b is the mean, and e is the constant value 2.71828; the following is an example of a 3x3 Gaussian matrix:
[0101]
[0102] According to the above formula, first create a one-dimensional double-precision matrix mask of size d by getGaussianKernel in opencv, and then create a two-dimensional matrix according to matrix transposition and matrix product operations, the created Gaussian filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn, and the new kernel value is normalized, and the above evaluation process is encapsulated as a Gaussian filter kernel value function Gaussain_kernel with a type value of GAUSSIAN_KERNEL.
[0103] Step 4: After performing multiple convolution filtering processes on the grayscale image input in step 1, output the filtered image. The specific steps are:
[0104] Obtaining a difference image: inputting the grayscale image in step 1, performing multiple convolution filtering processes, each time using different smoothing kernels; calculating the difference between each convolution filtering result and the original image according to the convolution kernel, and obtaining multiple difference images convDiff;
[0105] Get the optimal convolution kernel: For each pixel in the grayscale image in S1, compare its value in multiple difference images, and select the convolution kernel corresponding to the difference image minIndex with the smallest value as the optimal convolution kernel;
[0106] Restore the denoised grayscale image: According to the selection result of the optimal convolution kernel, enhance the original image, replace the value of each pixel in the grayscale image with its corresponding value in the optimal convolution kernel filtering result, and add an adjustment amount based on the original pixel value to form the current pixel. Repeat the above steps until the predetermined number of iterations is reached to obtain the new image grays after filtering and enhancement.
[0107] Output the filtered image: Convert the new image grays after filtering and enhancement into a format suitable for display or storage, and output grayResult as the filtered image.
[0108] The first scenario: When the selected smoothing kernel shapes are Gaussian filter kernel and bilateral filter kernel.
[0109] Select a small amount of bacillus biological image under a microscope, and choose to use the Gaussian filter kernel type GAUSSIAN_KERNEL, r = 20, iteration = 5 and the bilateral filter kernel type BILATERAl_KERNEL, r = 20, iteration = 5 respectively under the same kernel size; the Gaussian filter kernel smoothes the entire image more evenly and has a better effect on retaining the edges of the fungi. The results of the Gaussian filter kernel are as follows Figure 4 As shown, Figure 4 This is an example of circular window filtering with a Gaussian filter kernel as the kernel shape. The bilateral filter kernel smoothes the entire image by the pixel difference size. Small ones are Gaussian blurred, fungi are partially blurred by Gaussian, and large ones will reduce the kernel function, thereby maintaining the edge details of the image. The edges of objects are well preserved. The bilateral filter kernel results are as follows: Figure 5 As shown, Figure 5 This is an example of circular window filtering with a bilateral filter kernel selected as the kernel shape.
[0110] The second scenario: changing the size of the kernel d under the same filter kernel, when iteration = 5.
[0111] Choose any medical biological image obtained under a microscope and change the size of the input value r to 5 and 15 respectively, because d = 2*r+1, d is the size of the matrix template, that is, the size of the kernel, and the shape of the kernel is the Gaussian filter kernel; when the Gaussian filter kernel d = 5, more original image information is retained, and the edge information of the target object is also well preserved. The results are as follows Figure 6 As shown, Figure 6 This is an example of a circular window filter with a kernel size of (5,5) and a Gaussian filter kernel shape. When the Gaussian filter kernel d=15, some information of the original image is lost, but the edge information of the target object is well preserved. The results are as follows: Figure 7 As shown, Figure 7 This is an example of a circular window filter with a kernel size of (15,15) and a Gaussian kernel shape.
[0112] The third scenario: When a salt and pepper noise is added, bilateral filter kernels and Gaussian filter kernels of the same size are selected for filtering.
[0113] First, a salt and pepper noise is added to the selected biomedical image, and then the image is grayscale processed to obtain a salt and pepper noise grayscale image, such as Figure 8 As shown, Figure 8 This is a single-channel grayscale example image with salt and pepper noise added. First, select the bilateral filter kernel, under the conditions of r=15, iteration=5, and create circular and semicircular masks, and then filter the grayscale image with salt and pepper noise added. The results are as follows: Fig. 9 As shown, Fig. 9This is an example of using a bilateral filter kernel to filter out salt and pepper noise using a circular window filter. Most of the noise is filtered out, and the characteristic information of the objects in the image is retained.
[0114] Next, we select the Gaussian filter kernel, create circular and semicircular masks under the conditions of r=15, iteration=5, and filter the grayscale image with salt and pepper noise. The results are as follows: Fig.10 As shown, Fig.10 This is an example of using a Gaussian filter kernel's circular window filter to remove salt and pepper noise. Most of the noise is filtered out, and the characteristic information of the objects in the image is retained.
[0115] Comparison: Comparison of the effects of circular and rectangular masks on image filtering
[0116] A medical biological image under a microscope is selected and grayscale processing is performed on the image; a rectangular mask filter function and a circular and semicircular mask filter function of the present invention are respectively created in eight regions in different directions; under the same other conditions, the filter kernel is a mean filter kernel, r=15, iteration=5, and the grayscale image is filtered. The image results after the circular and semicircular mask filtering of the present invention are as follows: Fig.11 As shown, Fig.11 The following is an example of using the circular and semicircular mask windows of the present invention to filter an image. The edge information can be mostly retained, and more image information is retained. In the image filtered by the rectangular mask, the edge of the bacillus is retained, but the image information is less than that of the image filtered by the circular and semicircular mask windows of the present invention. The results are shown in FIG. Fig.12 As shown, Fig.12 An example of filtering an image using a rectangular masked window.
[0117] Different from the prior art, the image filtering method provided by the present application includes: reading image information; creating circular masks in different directions; establishing different types of smoothing kernels; after multiple convolution filtering processes, outputting the filtered image. The present invention can directly perform filtering through the created template and four circular masks in different directions, with high efficiency, and can effectively remove noise in the target and background. In addition, through the newly created four templates and four semicircular masks in different directions, complete coverage is achieved, and the noise in the target and background is further effectively removed. In addition, the newly created bilateral smoothing kernel or Gaussian smoothing kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn, and the final eight smoothing kernels are obtained after normalization; not only can the noise in the target and background be effectively removed, but also the shape, size and specific geometric and topological structure features of the image target can be well protected.
[0118] The above description shows the main features, basic principles, and advantages of the present invention. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above exemplary embodiments or examples, and the present invention can be implemented in other specific forms without departing from the spirit or basic features of the present invention. Therefore, the above embodiments or examples should be regarded as exemplary and non-restrictive. The scope of the present invention is defined by the attached claims rather than the above description, and it is intended to include all changes within the meaning and scope of the equivalent elements of the claims in the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. Any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the technical principle of the present invention shall fall within the scope of patent protection of the present invention.
Claims
1. An image filtering method, characterized in that: The following steps are involved: S1: Read image information: read the collected biological microscopic image, convert the three-channel color image into a single-channel grayscale image, and read the pixel information in the grayscale image; S2: Create circular masks in different directions: S21: normalize the image read by S1, obtain its width and height from the normalized image, and store these size information in corresponding variables; S22: Create four d-dimensional array templates. The template size calculation formula is as follows: d=2·r+1, Among them, d is the size value of the template, and r is the diameter value of the given circle; S23: According to the four templates created, four circular masks in different directions are created clockwise respectively, and then the circular masks in the four different directions are stored in the container. The coordinate formulas of the center points of the circular masks in the four different directions are: Where r is the diameter of a given circle; i represents the azimuth value, which can be LU, RU, RD, or LD; n can be 0, 1, 2, or 3, respectively. in (x, y) is the coordinate position of the center point of the circle, mod means the remainder after dividing by 2; S3: Establish different types of smoothing kernels; S4: After performing multiple convolution filtering processes on the grayscale image in S1, the filtered image is output.
2. An image filtering method as claimed in claim 1, characterized in that: In step S23, four new templates are added based on the four original templates, and semicircular masks in four different directions are created clockwise in sequence according to the four new templates, and then the semicircular masks in four different directions are stored in the container. The coordinate formulas of the center points of the semicircular masks in four different directions are: D=d, Among them, D is the diameter of the semicircle, d is the size of the template, j represents the orientation value, which can be L, U, R, or D respectively; n can be 0, 1, 2, or 3 respectively, and N jn (x, y) is the coordinate position of the center point of the semicircle, and mod means the remainder after dividing by 2.
3. An image filtering method as claimed in claim 2, characterized in that: The specific steps of establishing different types of smoothing kernels in S3 are: S31: Create different types of intermediate kernels: bilateral filter kernel, Gaussian filter kernel, select the bilateral filter kernel for filtering and create a new bilateral smoothing kernel, or select the Gaussian filter kernel for filtering and create a new Gaussian smoothing kernel; S32: performing product operations on the newly created bilateral smoothing kernel or Gaussian smoothing kernel, the circular masks in the four different directions, and the semicircular masks in the four different directions in sequence, and obtaining the final eight smoothing kernels after normalization.
4. An image filtering method as claimed in claim 3, characterized in that: The steps of creating the bilateral filter kernel are as follows: bilateral filtering uses both spatial Gaussian weights and gray value similarity Gaussian weights; Mat is used to first create an all-zero matrix of d, and then the value of the bilateral filter kernel is calculated according to the following formula: Among them, f(k,l) is the pixel value corresponding to the center coordinate point (k,l) of the template window, (n,m) is the coordinate of other coefficients of the template window, and w(n,m,k,l) is the weight value of the coordinate of the center point of the template window and the coordinate of other coefficients; The kernel value of each coordinate point is obtained and put into the all-zero matrix of the template size d created previously. After creation, the bilateral filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn. The new kernel value is normalized again, and the above evaluation process is encapsulated as a bilateral filter kernel value function Bilateral_kernel with a type value of BILATERAl_KERNEL.
5. An image filtering method as claimed in claim 3, characterized in that: The steps of creating the Gaussian filter kernel are as follows: the Gaussian kernel is mainly created by a Gaussian function, and the Gaussian function formula is as follows: Among them, a is a constant related to the standard deviation c, c is the standard deviation, b represents the mean, and e represents the constant value 2.71828; According to the above formula, first create a one-dimensional double-precision matrix mask of size d by getGaussianKernel in opencv, and then create a two-dimensional matrix according to matrix transposition and matrix product operations, the created Gaussian filter kernel is multiplied with the circular masks in four different directions and the semicircular masks in four different directions in turn, and the new kernel value is normalized, and the above evaluation process is encapsulated as a Gaussian filter kernel value function Gaussain_kernel with a type value of GAUSSIAN_KERNEL.
6. An image filtering method as claimed in claim 3, characterized in that: S4 performs multiple convolution filtering processes on the grayscale image in S1 and outputs the filtered image. The specific steps are as follows: S41: Obtaining a difference image: inputting the grayscale image in S1, performing multiple convolution filtering processes, each time using different smoothing kernels; calculating the difference between each convolution filtering result and the original image according to the convolution kernel, and obtaining multiple difference images convDiff; S42: Obtain the optimal convolution kernel: for each pixel in the grayscale image in S1, compare its value in multiple difference images, and select the convolution kernel corresponding to the difference image minIndex with the smallest value as the optimal convolution kernel; S43: restore the grayscale image after denoising: according to the selection result of the optimal convolution kernel, enhance the original image, replace the value of each pixel in the grayscale image with its corresponding value in the optimal convolution kernel filtering result, and add an adjustment amount based on the original pixel value to form the current pixel, repeat the above steps until the predetermined number of iterations is reached, and obtain the new image grays after filtering and enhancement processing; S44: Outputting the filtered image: converting the new image grays after filtering and enhancement processing into a format suitable for display or storage, and outputting grayResult as the filtered image.
Citation Information
Patent Citations
Filtering operation method of circular filter
CN113746451A