Disclosure of Invention
The application aims to solve the defects of the prior art and provides an image filtering method, an image filtering device and a storage medium for reserving image edges, which can obtain a repaired image with complete edges.
In order to achieve the above purpose, the present application adopts the following technical scheme:
an image filtering method for preserving image edges is provided, which comprises the following steps:
step 101, acquiring a target image, extracting a contour line in the target image, and forming a first image by the extracted contour line and an empty template image with the same size as the original image;
102, performing image restoration on a target image to obtain a second image;
step 103, performing image enhancement processing on the repaired second image to obtain a third image;
and 104, performing image superposition on the first image and the third image to obtain a fourth image, and outputting the fourth image as a target image.
Further, the method for extracting the contour line in the target image is to extract the contour feature of the image by a Canny operator, and specifically includes the following steps:
step 201, performing image smoothing processing on a target image by using a Gaussian filter;
step 202, calculating the amplitude and direction of the gradient of the smoothed image by using the finite difference of the first-order bias;
step 203, performing non-maximum value inhibition processing on the gradient amplitude of the smoothed image;
step 204, performing dual-threshold algorithm detection and connection edge processing on the image processed in step 203.
Further, the above-mentioned method for performing image restoration on the target image to obtain the second image specifically includes the following steps:
step 301, using P to represent a complete area of a target image, and determining Q as an area to be repaired of the target image, wherein P-Q is an area without repair of the target;
step 302, calculating each pixel point a of the edge of the to-be-repaired area Q of the target image, and calculating the to-be-repaired block M centered on the pixel point a a Repair priority a of (2):
A(a)=C(a)D(a),
wherein C (a) designs the block E to be repaired a Is the confidence factor term of the block to be repaired E a WhereinIn |M a I is the block M to be repaired a α is a normalization factor;a unit vector representing an edge perpendicular to the region Q to be repaired at the point a;
step 303, finding out pixel points corresponding to the MAX A (a) value in the edge points of the to-be-repaired area Q, repairing the to-be-repaired block centered on the pixel points corresponding to the MAX A (a) value, and completing the repair of the to-be-repaired block M a Is set to 0;
step 304, repeating step 303 until the area Q to be repaired is completely repaired to obtain a second image.
Further, the repairing process in step 303 includes the following steps:
step 401, calculating a block M to be repaired a The gray value of the known pixel and the Euclidean distance d of the gray value in the corresponding block in the image without repairing area, and the block with the minimum Euclidean distance is taken as the block M to be repaired a Is the best matched image block N of (2) a ;
Step 402, according to the best matching image block N a Gray value of middle pixel point is to repair block M a Filling gray values in pixel points of (2), and after filling, filling the block M to be repaired a Marking as a repair-free area;
step 403, the image processed in step 402 is processed again according to steps 401 to 402 until the area to be repaired is completely repaired.
Further, the specific way of performing image superposition on the first image and the third image to obtain the fourth image includes the following steps:
and performing image superposition operation on the first image and the third image through matlab, and setting RGB values of an empty template image of the first image except for the extracted contour line part to be 0.
An image filtering device for preserving image edges is also provided, and the image filtering method for preserving image edges is applied, and comprises the following steps:
the contour line extraction module is used for extracting contour lines in the target image, and the extracted contour lines and the blank template image with the same size as the original image form a first image together;
the image restoration module is used for carrying out image restoration on the target image to obtain a second image;
the image enhancement module is used for carrying out image enhancement processing on the repaired second image to obtain a third image;
and the image superposition module is used for carrying out image superposition on the first image and the third image to obtain a fourth image, and outputting the fourth image as a target image.
Further, the image restoration module includes:
the device comprises a to-be-repaired area determining subunit, a target image processing subunit, a processing unit and a processing unit, wherein the to-be-repaired area determining subunit is used for determining the to-be-repaired area of the target image;
a pixel point calculating subunit, configured to calculate each pixel point a of the edge of the to-be-repaired area Q of the target image;
a repair priority calculating subunit for calculating a block M to be repaired centered on the pixel point a a Is assigned repair priority a.
A computer-readable storage medium storing a computer program is also proposed, which when executed by a processor implements the steps of the image filtering method preserving image edges.
The beneficial effects of the application are as follows:
according to the application, the image edge is extracted, and then the edge image of the image and the repaired image are subjected to image superposition to obtain the repaired image with the complete edge, so that the damage to the image edge in the image repairing process can be avoided, and the clear and complete repaired image is obtained.
Detailed Description
The conception, specific structure, and technical effects produced by the present application will be clearly and completely described below with reference to the embodiments and the drawings to fully understand the objects, aspects, and effects of the present application. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The same reference numbers will be used throughout the drawings to refer to the same or like parts.
In conjunction with fig. 1, the present application proposes an image filtering method for preserving image edges, including:
step 101, acquiring a target image, extracting a contour line in the target image, and forming a first image by the extracted contour line and an empty template image with the same size as the original image;
102, performing image restoration on a target image to obtain a second image;
step 103, performing image enhancement processing on the repaired second image to obtain a third image;
and 104, performing image superposition on the first image and the third image to obtain a fourth image, and outputting the fourth image as a target image.
According to the application, the image edge is extracted, and then the edge image of the image and the repaired image are subjected to image superposition to obtain the repaired image with the complete edge, so that the damage to the image edge in the image repairing process can be avoided, and a clear and complete repaired image is output.
In a preferred embodiment of the present application, the method for extracting the contour line in the target image is to extract the contour feature of the image by a Canny operator, and specifically includes the following steps:
step 201, performing image smoothing processing on a target image by using a Gaussian filter;
step 202, calculating the amplitude and direction of the gradient of the smoothed image by using the finite difference of the first-order bias;
step 203, performing non-maximum value inhibition processing on the gradient amplitude of the smoothed image;
step 204, performing dual-threshold algorithm detection and connection edge processing on the image processed in step 203.
According to the method, edge extraction is carried out on the contour line of the target image by adopting a Canny operator, and the Canny is added with two improvements of non-maximum value inhibition and double threshold on the basis of a first-order differential operator. The non-maximum value inhibition is utilized to effectively inhibit the multi-response edge, and the positioning accuracy of the edge can be improved; the double threshold can effectively reduce the omission ratio of the edge.
As a preferred embodiment of the present application, the above-mentioned method for performing image restoration on the target image to obtain the second image specifically includes the following steps:
step 301, using P to represent a complete area of a target image, and determining Q as an area to be repaired of the target image, wherein P-Q is an area without repair of the target;
step 302, calculating each pixel point a of the edge of the to-be-repaired area Q of the target image, and calculating the to-be-repaired block M centered on the pixel point a a Repair priority a of (2):
A(a)=C(a)D(a),
wherein C (a) designs the block E to be repaired a Is the confidence factor term of the block to be repaired E a WhereinIn |M a I is the block M to be repaired a α is a normalization factor;a unit vector representing an edge perpendicular to the region Q to be repaired at the point a;
step 303, finding out pixel points corresponding to the MAX A (a) value in the edge points of the to-be-repaired area Q, repairing the to-be-repaired block centered on the pixel points corresponding to the MAX A (a) value, and completing the repair of the to-be-repaired block M a Is set to 0;
step 304, repeating step 303 until the area Q to be repaired is completely repaired to obtain a second image.
According to the method and the device, the repair priority is calculated, and the repair blocks with the repair areas are repaired sequentially according to the priority, so that the repair accuracy can be guaranteed to a certain extent.
As a preferred embodiment of the present solution, the repairing process in step 303 includes the following steps:
step 401, calculating a block M to be repaired a The gray value of the known pixel and the Euclidean distance d of the gray value in the corresponding block in the image without repairing area, and the block with the minimum Euclidean distance is taken as the block M to be repaired a Is the best matched image block N of (2) a ;
Step 402, according to the best matching image block N a Gray value of middle pixel point is to repair block M a Filling gray values in pixel points of (2), and after filling, filling the block M to be repaired a Marking as a repair-free area;
step 403, the image processed in step 402 is processed again according to steps 401 to 402 until the area to be repaired is completely repaired.
In the present embodiment, the euclidean distance is calculated so that the point in the repair-free region of the nearest euclidean distance is used as the best matching image block N a Gray value of middle pixel point is to repair block M a The gray values in the pixels of (a) are filled, so that the continuity of the image can be ensured to a certain extent.
As a preferred embodiment of the present application, the specific manner of performing image superposition on the first image and the third image to obtain the fourth image includes the following:
and performing image superposition operation on the first image and the third image through matlab, and setting RGB values of an empty template image of the first image except for the extracted contour line part to be 0.
In the present embodiment, when the first image and the third image are superimposed, the RGB values of the blank template image excluding the extracted contour line portion of the first image are set to 0 at the same time, so that the situation in which the images overlap at positions other than the contour lines of the first image and the third image can be avoided.
An image filtering device for preserving image edges is also provided, and the image filtering method for preserving image edges is applied, and comprises the following steps:
the contour line extraction module is used for extracting contour lines in the target image, and the extracted contour lines and the blank template image with the same size as the original image form a first image together;
the image restoration module is used for carrying out image restoration on the target image to obtain a second image;
the image enhancement module is used for carrying out image enhancement processing on the repaired second image to obtain a third image;
and the image superposition module is used for carrying out image superposition on the first image and the third image to obtain a fourth image, and outputting the fourth image as a target image.
As a preferred embodiment of the present solution, the image restoration module includes:
the device comprises a to-be-repaired area determining subunit, a target image processing subunit, a processing unit and a processing unit, wherein the to-be-repaired area determining subunit is used for determining the to-be-repaired area of the target image;
a pixel point calculating subunit, configured to calculate each pixel point a of the edge of the to-be-repaired area Q of the target image;
a repair priority calculating subunit for calculating a block M to be repaired centered on the pixel point a a Is assigned repair priority a.
A computer-readable storage medium storing a computer program is also proposed, which when executed by a processor implements the steps of the image filtering method preserving image edges.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical modules, i.e., may be located in one place, or may be distributed over a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The integrated modules may be implemented in hardware or in software functional modules.
While the present application has been described in considerable detail and with particularity with respect to several described embodiments, it is not intended to be limited to any such detail or embodiments or any particular embodiment, but is to be construed as providing broad interpretation of such claims by reference to the appended claims in view of the prior art so as to effectively encompass the intended scope of the application. Furthermore, the foregoing description of the application has been presented in its embodiments contemplated by the inventors for the purpose of providing a useful description, and for the purposes of providing a non-essential modification of the application that may not be presently contemplated, may represent an equivalent modification of the application.
The present application is not limited to the above embodiments, but is merely preferred embodiments of the present application, and the present application should be construed as being limited to the above embodiments as long as the technical effects of the present application are achieved by the same means. Various modifications and variations are possible in the technical solution and/or in the embodiments within the scope of the application.