Disclosure of Invention
Aiming at the defects, the invention provides a method for combining morphological filtering and bilateral filtering algorithms to process the depth image, fills the holes in the depth image by several basic algorithms in morphology, and then smoothes the image by bilateral filtering.
The purpose of the invention is: the processed image is clearer, and accurate depth information is easy to extract.
The technical scheme adopted by the invention for realizing the purpose is as follows: an algorithm for the restoration of a depth image,
the steps of the algorithm are as follows:
the method comprises the following steps: establishing expansion, corrosion, opening operation and closing operation formulas of a morphological algorithm;
step two: establishing a morphological filter;
step three: selecting structural elements;
step four: and establishing a bilateral filtering criterion.
The invention has the beneficial effects that: the invention processes the depth image by combining the morphological filtering and the bilateral filtering algorithm, fills the holes in the depth image by several basic algorithms in morphology, and then smoothes the image by utilizing the bilateral filtering. The morphological filtering is an image processing method which takes several basic operations in morphology as a core algorithm, and has better effect to a certain extent compared with the conventional linear filtering. It uses different structural elements to eliminate different types of noise signals contained in the target object.
Detailed description of the invention
In order to make the technical solution and the purpose of the present invention more clear, the present invention is further described below with reference to fig. 1 to 4.
The invention processes the depth image based on a method combining morphological filtering and bilateral filtering. The morphological filtering is mainly based on mathematical morphology, is a nonlinear filtering form and is formed by combining basic algorithms such as expansion, corrosion, opening and closing operations and the like. The image structure is analyzed by gathering related ideas, so that the morphological essence of the object can be intuitively obtained, and the analysis and the processing are easy. Therefore, the characteristic of the depth image is utilized to process the holes in the depth image, the image can be slightly rough after the processing is finished, and the depth image has a good smooth image function by combining bilateral filtering, so that the processed image is clearer, and accurate depth information is easy to extract.
Morphology includes many different methods, such as dilation, erosion, open and close operations, etc., with dilation and erosion being the most basic operations.
Firstly, establishing expansion, corrosion, opening operation and closing operation formulas of morphological algorithm
Setting f as an image function, s as a structural element, DfAnd DgThe domains are denoted f, s, respectively.
1. Establishing an expansion equation, in conjunction with FIG. 2
The main function of the expansion is to expand the edge of the target object and to enlarge the object range, so that the isolated part contacted with the object can be integrated into the object itself, and the expansion formula is defined in the method as follows:
and (x, y) ∈ Dg}
2. Establishing an etching formula in combination with FIG. 3
The effect of erosion is just opposite to the expansion, which is mainly to shrink the edge of the target object inwards, and in this method, the formula of erosion is defined as:
(fΘs)(t,m)=min{f(t+x,m+y)-s(x,y)|(t+x),(m+y)∈Dfand (x, y) ∈ Dg}
3. Establishing an open operation formula
Firstly, carrying out corrosion operation and then carrying out expansion operation, wherein the process is opening operation, the opening operation can remove single dots, burrs and bridges in the image and can smooth the edge of an object, and the formula of the opening operation is defined as:
4. establishing a closed operation formula
The method comprises the following steps of firstly performing expansion operation and then performing corrosion operation, wherein the process is closed operation, the closed operation can fill fine holes existing in a target object and repair fine cracks and smooth edges of the object (the closed operation is filtered by filling concave angles of an image), and a formula of the closed operation is defined as follows:
secondly, establishing a morphological filter, combining with the figure 4
The method comprises the following steps that isolated and burr points in an image can be removed through open operation, fine cracks in the image can be filled through closed operation, if image filtering is carried out through open and close independently, the problem of statistical deviation occurs due to the characteristics of the image filtering, the filtering effect is poor, and therefore open and close operations need to be combined for use, namely, the open and close filtering can cause the result amplitude to be small, the closed filtering can cause the result to be large, and therefore the two operations are averaged for use:
the on-off filtering formula:
fOC=f○S●S
closed-open filter formula:
fco=f●SOS
a combination formula is adopted:
thirdly, selecting structural elements
The selection of the structural elements plays a crucial role in morphological filtering, and the size and shape of the structural elements influence the filtering result, so that the appropriate structural elements should be selected, and circular structural elements are adopted in the invention.
Fourthly, establishing a bilateral filtering criterion
Bilateral filtering is a nonlinear filtering bilateral filtering composed of two kernel functions, which not only refers to the correlation in the spatial domain, but also refers to the similarity of pixel values. Therefore, the filtering can be carried out while the image edge information in the image information is considered, so that the fuzzy edge information of the image after normal Gaussian filtering can be kept clear, and the image edge is smoother.
The expression of the gaussian kernel is:
wherein,gthe standard deviation of the gaussian function is represented, the gaussian kernel function only considers the spatial relationship of the pixels and does not pay attention to the gray value change of the image, so that the edges are smoothed during filtering, and the filtering result tends to be blurred. Therefore, the bilateral filtering is to add a function to constrain the change of the gray value of the image. Therefore, the above expression is transformed into:
in the formula,Rrepresents the standard deviation of the transformed gaussian function, so the weighting coefficients for the bilateral filtering are:
H=HsHr
if the gray values of (i, j) and (x, y) are close, the weight coefficient H will tend to be Hs. The result will tend to be that of gaussian filtering. The result of the bilateral filtering depends ongAndrtwo parameters aregIs fixed torIf the value of (3) is large, the weight coefficient H is also large, and the effect of preserving edges is not achieved as in the case of gaussian filtering. But whenrWhen the value of (a) is small, the filtering effect is lost, so that the selection of proper parameters for filtering is important.