MATLAB image processing learning - image enhancement technology (with image enhancement method code)

Table of contents

1. Introduction

(1) Introduction to image enhancement technology

(2) Image quality assessment

2. Image enhancement in the spatial domain

 (1) Display grayscale histogram

 (2) Image gray value adjustment

 (3) Image brightness adjustment

 (4) Inversion transformation of grayscale image

 3. Histogram enhancement

 (1) Color histogram of RGB color image

 (2) Histogram equalization

 (3) Histogram specification


1. Introduction

(1) Introduction to image enhancement technology

    Image enhancement technology generally highlights or enhances certain features of the image, such as edge information, contour information, and contrast, so as to better display the useful information of the image and improve the use value of the image.

    Most of the traditional image enhancement techniques are based on image processing in the spatial domain. (Image enhancement techniques in the spatial domain mainly include grayscale transformation and histogram methods , etc.)

    The image can be converted from the spatial domain to the frequency domain by Fourier transform, filtered in the frequency domain, and then converted to the spatial domain using the inverse Fourier transform.

(2) Image quality assessment

    Image quality includes two aspects. One is the fidelity of the image , that is, the degree of deviation between the evaluated image and the original standard image; the other is the intelligibility of the image , which refers to the ability of the image to provide information to humans or machines.

    Image quality evaluation methods are divided into subjective evaluation and objective evaluation.

2. Image enhancement in the spatial domain

(1) Display grayscale histogram

 You can use the imhist() method to obtain the histogram of the grayscale image, as follows:

imhist(I) : This function draws the histogram of the grayscale image I

imhist(I,n) : This function specifies the number of gray levels as n, and the default value of n is 256

imhist(X,map) : This function draws the histogram of the indexed image X

[counts,x]=imhist(...) : This function returns the data of the histogram, and the histogram can be drawn by using stem(x,counts)

Code (to get the histogram of a grayscale image):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
figure;
subplot(121),imshow(uint8(I));
subplot(122),imhist(I);

operation result:

 (2) Image gray value adjustment

The imadjust() method is provided in matlab to adjust the gray value of the image, and the calling method is as follows:

J=imadjust(I) : This function adjusts the grayscale of the image I

J=imadjust(I,[low_in;high_in],[low_out;high_out]): In this function, [low_in;high_in] is the grayscale range to be transformed in the original image, and [low_out;high_out] is the transformed grayscale range

J=imadjust(I,[low_in;high_in],[low_out;high_out],gamma) : The gamma in this function is the way of mapping, and the default value is 1, that is, linear mapping. When gamma is not equal to 1, it is a nonlinear mapping.

RGB2=imadjust(RGB1,... ) : This function adjusts the RGB1 of the color image

Code (adjust image gray value):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
J=imadjust(I,[0.2;0.5],[0;1]);
figure;
subplot(121),imshow(uint8(I));
subplot(122),imshow(uint8(J));

operation result:

 Code (adjust grayscale image brightness):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
J=imadjust(I,[0.2;0.5],[0;1],0.4);
K=imadjust(I,[0.1;0.5],[0;1], 4);
figure;
subplot(121),imshow(uint8(J));
subplot(122),imshow(uint8(K));

operation result:

 Code (enhanced color image):

close all;clear all;clc;
I=imread('D:/resource_photo/4.jpg');
J=imadjust(I,[0.2 0.3 0;0.6 0.7 1],[]);
figure;
subplot(121),imshow(uint8(I));
subplot(122),imshow(uint8(J));

operation result:

 (3) Image brightness adjustment

In matlab, the brightness of the grayscale image can also be changed through the function brighten(), and the calling method is as follows:

brighten(beta) : This function changes the brightness of the image. If beta is greater than 0 and less than 1, the image becomes brighter; if beta is less than 0 and greater than -1, the image becomes darker.

brighten(h,beta) : This function operates on the image with handle h

Code (to adjust the brightness of a grayscale image):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
figure,imshow(I);brighten(0.6);%图像变亮
figure,imshow(I);brighten(-0.6)%图像变暗

operation result:

 Code (image enhancement via function stretchlim() and function imadjust()):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
M=stretchlim(I);
J=imadjust(I,M,[]);
figure,imshow(uint8(I));
figure,imshow(uint8(J));

(In the program, use the function stretchlim() to obtain the best input range, then use the function imadjust() to adjust the grayscale, and finally achieve the effect of grayscale image enhancement)

operation result:

 (4) Inversion transformation of grayscale image

Use the method imcomplement() to invert the grayscale image.

Code (inverse transform of grayscale image):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
J=imcomplement(I)
figure,imshow(uint8(I));
figure,imshow(uint8(J));

operation result:

 3. Histogram enhancement

(1) Color histogram of RGB color image

Use the imhist method provided by matlab.

Code (to calculate the color histogram of an RGB color image):

close all;clear all;clc;
I=imread('D:/resource_photo/4.jpg');
figure;
subplot(141);imshow(uint8(I));
subplot(142);imhist(I(:,:,1));
title('R');
subplot(143);imhist(I(:,:,2));
title('G');
subplot(144);imhist(I(:,:,3));
title('B');

operation result:

 (2) Histogram equalization

The function histeq() is provided in the matlab image processing toolbox for histogram equalization processing. The specific calling method is as follows:

J=histeq(I,n) : In this function, I is the original input image, J is the image obtained by histogram equalization, n is the number of gray levels after equalization, and the default value is 64

Code (histogram equalization processing):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
J=histeq(I);
figure;
subplot(121);imshow(uint8(I));
subplot(122);imshow(uint8(J));
figure;
subplot(121);imhist(I,64);
subplot(122);imhist(J,64);

operation result:

 

 (3) Histogram specification

J=histeq(I,hgram): In this function, hgram is an integer vector, indicating the shape of the histogram desired by the user.

Code (for histogram specification of an image):

close all;clear all;clc;
I=imread('D:/resource_photo/1(1).tif');
hgram=ones(1,256);
J=histeq(I,hgram);
figure;
subplot(121);imshow(uint8(J));
subplot(122);imhist(J);

operation result:

 

Guess you like

Origin blog.csdn.net/weixin_52135595/article/details/126890217