Image edge detection method and system based on bilateral filter
Technical Field
The invention relates to the technical field of image processing, in particular to an image edge detection method and system based on a bilateral filter.
Background
In image processing, it is often necessary to extract edges of objects in an image. The most basic method is to calculate the gradient of the image, i.e. the difference in brightness of neighboring pixels. Directly calculating the gradient is easy to generate false edges, and the existing edges are likely to be missed. The edge detection technology in the prior art cannot avoid false edges, reduce the image quality after image processing, and cannot further analyze images. The image edge detection is sensitive to noise, the noise is easy to be taken as an edge, and the edge of an object can be blurred if the noise is input into the image smoothly and indiscriminately, so that the edge is lost.
Accordingly, the prior art is yet to be improved and developed.
Disclosure of Invention
In view of the defects of the prior art, the present invention aims to provide an image edge detection method and system based on a bilateral filter, which aims to solve the problem that in the prior art, the image edge detection is sensitive to noise, the noise is easy to be regarded as an edge, and the edge of an object is blurred if the image is input smoothly without selection, so that the edge is lost.
The technical scheme of the invention is as follows:
an image edge detection method based on a bilateral filter is disclosed, wherein the method comprises the following steps;
A. acquiring an input image to be subjected to image processing, and calculating the brightness difference between all pixel points and adjacent pixel points in the image;
B. acquiring brightness data of all pixel points in the image after filtering;
C. calculating a gradient value of the filtered luminance information;
D. and when the gradient value is detected to be larger than the preset threshold value, the position of the corresponding pixel point is the image edge.
The image edge detection method based on the bilateral filter, wherein the step a specifically includes:
a1, obtaining an image to be subjected to image processing, and obtaining the brightness value of each color component of each pixel point in the image;
a2, calculating the brightness difference of the color component corresponding to the adjacent point in each color of each pixel point in all the pixel points in the image, and adding the sum to be used as the brightness difference of the current pixel point and the adjacent pixel point.
In the image edge detection method based on the bilateral filter, the pixel size of the image in the step a2 is marked as (X, Y), the current pixel point is marked as (X, Y), and then the brightness value of the red component of the current pixel point (X, Y) is marked as I
r(x, y), and recording the brightness value of the green component of the current pixel point (x, y) as I
g(x, y), and recording the brightness value of the blue component of the current pixel point (x, y) as I
b(x, y), the brightness difference between the current pixel point and the adjacent pixel point is recorded as
i and j are positive integers and satisfy-X/2. ltoreq. i.ltoreq.X/2 and-Y/2. ltoreq. j.ltoreq.Y/2
The calculation formula of (2) is as follows:
in the method for detecting an image edge based on a bilateral filter, if the luminance data filtered in step B is denoted as F (x, y), the luminance data is filtered in step B
Wherein σc、σdIs a smoothing parameter, m and n are the length and width of the filter window, respectively, and m and n satisfy 1. ltoreq. m.ltoreq.X/2 and 1. ltoreq. n.ltoreq.Y/2, i and j satisfy-m. ltoreq. i.ltoreq.m and-n. ltoreq. j.ltoreq.n.
The image edge detection method based on the bilateral filter includes:
c1, calculating gradient value of the filtered brightness information in the x direction, and marking the gradient value in the x direction as Gx(x, y) wherein
C2, calculating the gradient of the filtered brightness information in the y direction, and marking the gradient in the y direction as Gy(x, y) then
C3, calculating the total gradient of the filtered brightness information, wherein the total gradient is marked as G (x, y),
G(x,y)=|Gx(x,y)|+|Gy(x,y)|。
the image edge detection method based on the bilateral filter is characterized in that the preset threshold in the step D is marked as T, the image edge is marked as E (x, y),
the edge of the object in the image is located where the value of E (x, y) is 1.
An image edge detection system based on bilateral filter, wherein the system comprises:
the brightness difference calculation module is used for acquiring an input image to be subjected to image processing and calculating the brightness difference between all pixel points and adjacent pixel points in the image;
the filtering module is used for acquiring brightness data of all pixel points in the image after filtering;
the gradient calculation module is used for calculating gradient values of the filtered brightness information;
and the image edge acquisition module is used for determining the position of the corresponding pixel point as the image edge when the gradient value is detected to be larger than the preset threshold value.
The image edge detection system based on the bilateral filter, wherein the brightness difference calculation module specifically includes:
the brightness acquisition unit is used for acquiring an image to be subjected to image processing and acquiring the brightness value of each color component of each pixel point in the image;
and the computing unit is used for computing the brightness difference of color components corresponding to the adjacent points in each color of each pixel point in all the pixel points in the image and then adding the sum to be used as the brightness difference of the current pixel point and the adjacent pixel point.
The image edge detection system based on the bilateral filter is characterized in that the pixel size of the image in the brightness difference calculation module is marked as (X, Y), the current pixel point is marked as (X, Y), and then the brightness value of the red component of the current pixel point (X, Y) is marked as I
r(x, y), and recording the brightness value of the green component of the current pixel point (x, y) as I
g(x, y), and recording the brightness value of the blue component of the current pixel point (x, y) as I
b(x, y), the brightness difference between the current pixel point and the adjacent pixel point is recorded as
i and j are positive integers and satisfy-X/2. ltoreq. i.ltoreq.X/2 and-Y/2. ltoreq. j.ltoreq.Y/2
The calculation formula of (2) is as follows:
the image edge detection system based on the bilateral filter, wherein the brightness data filtered by the filtering module is recorded as F (x, y), then
Wherein σc、σdIs a smoothing parameter, m and n are the length and width of the filter window, respectively, and m and n satisfy 1. ltoreq. m.ltoreq.X/2 and 1. ltoreq. n.ltoreq.Y/2, i and j satisfy-m. ltoreq. i.ltoreq.m and-n. ltoreq. j.ltoreq.n.
The invention provides an image edge detection method and system based on a bilateral filter. The filtering algorithm reduces the noise in the original image, especially the amplitude of common white noise, so that the occurrence probability of false edges is reduced. The edge part is strengthened while removing noise and fluctuation of the non-edge part, so that stability and accuracy of edge detection are enhanced.
Drawings
FIG. 1 is a flowchart illustrating an image edge detection method based on bilateral filter according to a preferred embodiment of the present invention.
FIG. 2 is a functional block diagram of a preferred embodiment of a bilateral filter-based image edge detection system according to the present invention.
Detailed Description
In order to make the objects, technical solutions and effects of the present invention clearer and clearer, the present invention is described in further detail below. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The present invention also provides a flowchart of a preferred embodiment of a bilateral filter-based image edge detection method, as shown in fig. 1, wherein the method includes:
step S100, an input image to be subjected to image processing is obtained, and the brightness difference between all pixel points in the image and adjacent pixel points is calculated.
Specifically, in the case of daily image processing, it is necessary to acquire an edge of an image in advance. The image in the embodiment of the present invention refers to a color image. The image to be processed may be taken as an input image, and data of the input image may be acquired. And calculating the brightness difference value of each pixel point and the adjacent pixel point in all the pixel points in the input image.
In specific implementation, the step S100 specifically includes:
s101, acquiring an image to be subjected to image processing, and acquiring the brightness value of each color component of each pixel point in the image;
step S102, calculating the brightness difference of color components corresponding to adjacent points in each color of each pixel point in all pixel points in the image, and adding the sum to obtain the brightness difference of the current pixel point and the adjacent pixel point.
In specific implementation, the image in step S101 is a color image, and it is necessary to obtain the luminance values of the red, green, and blue color components of the image in advance. In step S102, the pixel size of the image is marked as (X, Y), the current pixel point is marked as (X, Y), and then the brightness value of the red component of the current pixel point (X, Y) is marked as I
r(x, y), and recording the brightness value of the green component of the current pixel point (x, y) as I
g(x, y), and recording the brightness value of the blue component of the current pixel point (x, y) as I
b(x, y), the brightness difference between the current pixel point and the adjacent pixel point is recorded as
i and j are positive integers and satisfy-X/2. ltoreq. i.ltoreq.X/2 and-Y/2. ltoreq. j.ltoreq.Y/2
The calculation formula of (2) is as follows:
and S200, acquiring the brightness of all pixel points in the image after filtering.
In specific implementation, if the luminance data filtered in step S200 is denoted as F (x, y), the luminance data is filtered
Wherein σc、σdIs a smoothing parameter, m and n are the length and width of the filter window, respectively, and m and n satisfy 1. ltoreq. m.ltoreq.X/2 and 1. ltoreq. n.ltoreq.Y/2, i and j satisfy-m. ltoreq. i.ltoreq.m and-n. ltoreq. j.ltoreq.n.
And step S300, calculating gradient values of the filtered brightness information.
In the specific implementation, since the image is in the x and y directions in the matrix, the sum of the gradient values of the filtered luminance information in the x and y directions is calculated respectively to be the gradient value of the final luminance information.
Specifically, the step S300 specifically includes:
step S301, calculating gradient value of the filtered brightness information in the x direction, wherein the gradient value in the x direction is marked as Gx(x, y) wherein
Step S302, calculating the gradient of the filtered brightness information in the y direction, wherein the gradient of the y direction is marked as Gy(x, y) then
Step S303, calculating the total gradient of the filtered brightness information, wherein the total gradient is marked as G (x, y),
G(x,y)=|Gx(x,y)|+|Gy(x,y)|。
step S400, when the gradient value is detected to be larger than the preset threshold value, the position of the corresponding pixel point is the image edge.
In specific implementation, the threshold preset in step S400 is denoted as T, the image edge is denoted as E (x, y),
when the value of E (x, y) is 1, the edge of the object in the image is shown.
The invention provides an image edge detection algorithm based on a bilateral filter for detecting the edge of an image, and the non-edge part of the image obtained after filtering is smoother, while the edge part is strengthened, so that the edge obtained by calculating the gradient is more reliable. The filtering algorithm reduces the amplitude of noise in the original image, especially common white noise, so that the occurrence probability of false edges is reduced.
The present invention further provides a functional block diagram of a preferred embodiment of a bilateral filter-based image edge detection system, as shown in fig. 2, wherein the system comprises:
a brightness difference calculation module 100, configured to obtain an input image to be subjected to image processing, and calculate brightness differences between all pixel points in the image and adjacent pixel points; as described in the method examples above.
The filtering module 200 is configured to obtain brightness data of all pixel points in the image after filtering; as described in the method examples above.
A gradient calculating module 300 for calculating gradient values of the filtered luminance information; as described in the method examples above.
An image edge obtaining module 400, configured to, when it is detected that the gradient value is greater than a preset threshold value, determine that a position where the corresponding pixel point is located is an image edge; as described in the method examples above.
The image edge detection system based on the bilateral filter, wherein the brightness difference calculation module specifically includes:
the brightness acquisition unit is used for acquiring an image to be subjected to image processing and acquiring the brightness value of each color component of each pixel point in the image; as described in the method examples above.
The calculating unit is used for calculating the brightness difference of color components corresponding to adjacent points in each color of each pixel point in all pixel points in the image and then adding the brightness differences to be used as the brightness difference of the current pixel point and the adjacent pixel point; as described in the method examples above.
The image edge detection system based on the bilateral filter is characterized in that the pixel size of the image in the brightness difference calculation module is marked as (X, Y), the current pixel point is marked as (X, Y), and then the brightness value of the red component of the current pixel point (X, Y) is marked as I
r(x, y), and recording the brightness value of the green component of the current pixel point (x, y) as I
g(x, y), and recording the brightness value of the blue component of the current pixel point (x, y) as I
b(x, y), the brightness difference between the current pixel point and the adjacent pixel point is recorded as
i and j are positive integers and satisfy-X/2. ltoreq. i.ltoreq.X/2 and-Y/2. ltoreq. j.ltoreq.Y/2
The calculation formula of (2) is as follows:
as described in the method examples above.
The image edge detection system based on the bilateral filter, wherein the brightness data filtered by the filtering module is recorded as F (x, y), then
Wherein σc、σdIs a smoothing parameter, m and n are the length and width of the filter window respectively, and m and n satisfy, i and j satisfy-m is less than or equal to i is less than or equal to m and-n is less than or equal to j is less than or equal to n; as described in the method examples above.
In summary, the present invention provides an image edge detection method and system based on a bilateral filter, the method includes: acquiring an input image to be subjected to image processing, and calculating the brightness difference between all pixel points and adjacent pixel points in the image; acquiring brightness data of all pixel points in the image after filtering; calculating a gradient value of the filtered luminance information; and when the gradient value is detected to be larger than the preset threshold value, the position of the corresponding pixel point is the image edge. The invention can remove noise and fluctuation of non-edge part, and strengthen edge part, to improve edge detection stability and accuracy.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.