“This is the 10th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

preface

Hello! Friend!!!

Thank you very much for reading haihong’s article, if there are any mistakes in the article, please point out ~

 

Self-introduction ଘ(੭, ᵕ)੭

Nickname: Haihong

Tag: programmer monkey | C++ contestant | student

Introduction: because of C language to get acquainted with programming, then transferred to the computer major, had the honor to get some national awards, provincial awards… Has been confirmed. Currently learning C++/Linux/Python

Learning experience: solid foundation + more notes + more code + more thinking + learn English well!

Image Sharpening (Principles)

Image sharpening processing in order to make the edge of the image and contour line and the detail of the image is clear, smooth image blur the fundamental reason is that the image received an average or integral operation, thus on the inverse operation (such as differential operation, actually there is a difference) can make the image clear. What is the definition of an edge in an image? In image processing, the edge is the place where the gray value changes violently. The magnitude of the change is mathematically the first derivative of a function. Assuming that the first figure below is the gray function of the image, it can be seen that the place with rapid change in the middle should be the edge of the image. The second figure is the first derivative of figure 1. According to mathematical knowledge, the extreme value of the first derivative is the point that changes the fastest — the edge. The third figure is the second derivative of Figure 1. When the second derivative is 0, it can be seen that it is the edge of the image. So, to determine the edge of the image, we just need to find the point where the first derivative is the extremum or the second derivative is 0 (the second derivative is 0 is not an edge point, such as an image of the same color where the first derivative and the second derivative are both 0 and there is no edge).

So why do you use difference to find edges for continuous functions, the first derivative is the derivative, the second derivative is the same. However, the image is essentially a two-dimensional matrix, discrete. You can’t differentiate it. This is where the concept of difference comes in. If you can’t understand it, you can think of it as: continuous function is to find the derivative (differential), discrete function is to find the difference.

First derivative, second derivative difference proof

The difference method on the image

First order differential operator proof is often used

Second order operator proof

Image sharpening

Concept: Image sharpening is to compensate the contour of the image, enhance the edge of the image and the gray scale jump part, so that the image becomes clear, divided into spatial domain processing and frequency domain processing two categories. Image sharpening is to highlight the edges, contours, or features of some linear object elements on the image. This filtering method improves the contrast between the edge of the ground object and the surrounding pixels, so it is also called edge enhancement.

Image sharpening is done by making the edges of the image more prominent, which can be superimposed on the high frequency part of the original image.

Sobel operator

I=imread('a2.jpg'); % Read image I1= rGB2gray (I); % Turn color image into gray image imshow(I1),title(' original image '); The model = [1, 1-2,0,2; 1, 1]. [m,n]=size(I1); I2=double(I1); for i=2:m-1 for j=2:n-1 I2(i,j)=I1(i+1,j+1)+2*I1(i+1,j)+I1(i+1,j-1)-I1(i-1,j+1)-2*I1(i-1,j)-I1(i-1,j-1); End end figure, imshow(I2),title(' image after edge extraction '); I2 = I2 + double(I1); Figure, imshow(uint8(I2)),title(' sharpened image ');Copy the code

rendering

Robert operator

I=imread('a2.jpg'); % Read image I1= rGB2gray (I); % Turn color image into gray image imshow(I1),title(' original image '); The model = [0, 1, 1, 0]; [m,n]=size(I1); I2=double(I1); for i=2:m-1 for j=2:n-1 I2(i,j)=I1(i+1,j)-I1(i,j+1); End end figure,imshow(I2),title(' image after edge extraction '); I2 = I2 + double(I1); Figure, imshow(uint8(I2)),title(' sharpened image ');Copy the code

rendering

Prewitt operator

I=imread('a2.jpg'); I1=rgb2gray(I); Subplot (1,2,1); Imshow (I1), title (' artwork '); The model = [1, 1, 1, 1; 1, 1]. [m,n]=size(I1); I2=I1; for i=2:m-1 for j=2:n-1 tem=I1(i-1:i+1,j-1:j+1); tem=double(tem).*double(model); I2(i,j)=sum(sum(tem)); Uint8 (I2)),title(' image after edge extraction ');Copy the code

rendering Laplacian operator

I=imread('C:\Users\LiCongliang\Desktop\ digital image processing \tea.png'); I1=mat2gray(I); % realize image matrix normalization operation [m,n]=size(I1); newGrayPic=I1; % save one pixel from the edges of the image LaplacianNum=0; % LaplacianThreshold=0.2; % LaplacianThreshold=0.2; % set threshold for j = 2: m boundary extraction for k = 2-1% : LaplacianNum = n - 1 abs (4 * I1 (j, k) - I1 (j, k) - I1 (j + 1, k) - I1 (j, k + 1) - I1 (j, k - 1)); if(LaplacianNum > LaplacianThreshold) newGrayPic(j,k)=255; else newGrayPic(j,k)=0; end end end I2=rgb2gray(I); % Turn color image into gray image imshow(I2),title(' original image '); figure, imshow(newGrayPic); Title (' result of Laplacian operator ')Copy the code

rendering