Analysis of cv-Laplace operator sharpening

Source: Internet
Author: User
Tags mathematical functions

The main purpose of image sharpening is to highlight the details in the image or to enhance the blurred detail, which is usually caused by the error operation or the effect of the special image acquisition method. There are many ways to sharpen the image, which is mainly the method of differential operator to sharpen the image. In general, the response strength of a differential operator is related to the degree of mutation of the image at that point (operator applied).

The differential in mathematics describes the variation of successive functions with respect to each variable. However, in the image, the whole picture is made up of many pixels, so although the image has two directions: horizontal (x direction) and vertical (y direction), the values in these directions, that is, the X-and Y-values of the pixels, are discrete.   x:1,2,3,... N; y:1,2,3,... m; then we need to use discrete methods to represent the differential.

The differential of mathematical functions can be defined in different terms, and there are various ways to define these differences, however, any definition of first order differential must guarantee the following points: (1) The differential value is zero in the flat segment (the gray invariant area), and (2) the differential value is not 0 at the starting point of the grayscale ladder or ramp; (3) The differential value is nonzero along the slope. The definition of any second-order differential is similar: (1) The differential value in the flat area must be zero, (2) The differential value is not 0 at the starting point of the gray scale ladder or the ramp, and (3) the differential value is nonzero along the slope surface. Because we are dealing with the number, the value is limited, so the maximum gray level change is also limited, the shortest distance of change occurs between two adjacent pixels.

1. Principle of image enhancement based on First order differential

The first-order partial differential differential representation for a two-tuple function is as follows:

The differential for defining a two-tuple function is:

This describes the first-order differential variation of a pixel point (x, y) in an image. A simple summary of an operator would be a 2*2 matrix as follows

This operator is applied in the image to mean subtracting (x, y) the value of the pixel (x-1,y) from the value at (x, y) of the pixel value minus (x,y-1) and substituting the pixel value at (x, y). This represents a change in the image at (x, y), overlay The change with the original value (x, y), which can make the change more noticeable, that is, to magnify the change, thus achieving image sharpening.

2. Image enhancement processing based on second-order differential.

First, a discrete formula of second order differential is defined, and then a filter based on this type is constructed. What we are most concerned about is an isotropic filter, which has a response independent of the direction of the mutation of the image the filter is acting on. In other words, the isotropic filter is rotated unchanged, the original image after the rotation of the filter processing given the first image filtering, and then rotating the same result.

A two-dollar image function f (x, y) of the Laplace transform is defined as:

Because any order differential is a linear operation, the Laplace transform is also a linear operation.

In order to be more suitable for digital image processing, this equation needs to be represented as a discrete form. There are several ways to define discrete transformations through neighborhood processing, but no matter how they are defined, they must conform to the nature of the second-order differential treatment mentioned in 3.7.1 section. The definition of second order differential processing given in the previous section is the most common one. Considering that there are two variables, we use the following definitions for second-order partial differential in the x direction :

Similarly, in the y direction:

(3.7.1) The two-dimensional pull-out digital implementation can be added by the two components:

And the Laplace operator is obtained.

The meaning is the same as the first-order differential operator above.

This explains the use of differential operators, very simple, as above this is when processing the RGB value of each pixel, multiply the RGB three value of the pixel by 4 and then subtract the RGB value of four pixels on the left and right, note that R, G, and B are processed separately.

This is the expression of change, we want to sharpen the picture, we should add this change to the original pixel on the line, that is

The idea is simple.


For yourself. The sharpening process of the image based on the Laplace operator:

void Sharpen (const mat &IMG, Mat &result) {for (int j = 1; j < img.rows-1; ++j) {const UCHAR *previous = img.pt R<const uchar> (j-1); const UCHAR *current = Img.ptr<const uchar> (j); const Uchar *next = Img.ptr<const Ucha R> (j + 1); Uchar *output = Result.ptr<uchar> (j); for (int i = 1; i < 3 * (IMG.COLS-1); ++i)//This is based on RGB graphs, if non-RGB The diagram does not need this {*output++ = cv::saturate_cast<uchar> (5 * current[i]-current[i-1]-current[i + 1]-Previous[i]-next[i]) ;}} Result.row (0). Setto (cv::scalar (0)), Result.row (result.rows-1). Setto (cv::scalar (0)); Result.col (0). Setto (CV:: Scalar (0)); Result.col (result.cols-1). Setto (cv::scalar (0));}


The following is a code that uses the FITER2D function in OpenCV to implement sharpening operations with the Laplace operator

int main () {Mat img, resulta;img = Imread ("c:/users/administrator/desktop/bbb.jpg"); Cv::mat Kernela (3, 3, cv_32f, CV:: Scalar (0));//assigns kernel values kernela.at<float> (1, 1) = 5.0;kernela.at<float> (0, 1) = -1.0;kernela.at& Lt;float> (2, 1) = -1.0;kernela.at<float> (1, 0) = -1.0;kernela.at<float> (1, 2) =-1.0; Filter2d (IMG, Resulta, img.depth (), Kernela),//cout << img.rowrange (1, 4). Colrange (1, 4) << Endl;//cout < < Result.rowrange (1, 4). Colrange (1, 4) << endl;imwrite ("C:/users/administrator/desktop/solved.jpg", Resulta );//imshow ("Origin", IMG);//imshow ("Sharpening results", resulta); Waitkey (0); return 0;}


Original picture


Image after sharpening


Analysis of cv-Laplace operator sharpening

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.