Digital Image Processing: Experiment 2

Experiment 2. Image preprocessing

1. Please use the function command in Matlab:

(1) Display an original image (customized, it is recommended to use a low contrast);
(2) Use the histogram function to display the histogram of a custom image;
(3) Use the histogram equalization function to image Do the processing and display the processed image. .


Experimental steps:

  1. show an original image

  2. Use the histogram function imhist to display it in a histogram;

  3. Use the adapthisteq function and histeq function to process the image respectively;

  4. Use the imhist function to display the histogram of the image equalized by the adapthisteq function and the histeq function respectively;

Experimental Matlab program: (version 2016a)

1.	clear;  
2.	clc;  
3.	img = imread('hua.jpg');%读取图片  
4.	imggray=rgb2gray(img);%灰度处理  
5.	imggray1=adapthisteq(imggray);%用adapthisteq将图imggray进行直方图均衡化  
6.	imggray2=histeq(imggray);%用histeq将图imggray进行直方图均衡化  
7.	  
8.	subplot(3,2,1);  
9.	imshow(imggray);%显示灰度处理后的图  
10.	title('原图');  
11.	  
12.	subplot(3,2,2);  
13.	imhist(imggray);%显示直方图  
14.	title('原图直方图');  
15.	  
16.	subplot(3,2,3);  
17.	imshow(imggray1);%显示使用adapthisteq均衡后的原图  
18.	title('对原图进行adapthisteq均衡处理');  
19.	subplot(3,2,4);  
20.	imhist(imggray1);%显示使用adapthisteq均衡后的直方图  
21.	title('adapthisteq均衡后直方图');  
22.	  
23.	subplot(3,2,5);  
24.	imshow(imggray2);%显示使用histeq均衡后的原图  
25.	title('对原图进行histeq均衡处理');  
26.	subplot(3,2,6);  
27.	imhist(imggray1);%显示使用histeq均衡后的直方图  
28.	title('histeq均衡后直方图');  

Program description:

According to the search information, four functions were collected: imhist() function, histeq() function and apthisteq() function; the imhist function is used to display the histogram of the image, and the histeq function adapthisteq function is the equalization function of the image;
clear After the data is stored in the workspace, first read in a picture 1, because the imhist function can only handle two-dimensional data, so when processing an RGB image, it should be converted into a grayscale image. Obtain the grayscale image through the rgb2gray function, then use the histeq function and apthisteq function in the program to obtain the original image after equalization, and combine the imhist function to obtain the histeq equalized histogram and apthisteq equalized histogram;

Experimental effect:

insert image description here

experiment analysis:

Histogram equalization can widen the gray-scale interval of the image or make the gray-scale distribution uniform, thereby increasing the contrast, making the image details clear, and achieving the purpose of image enhancement.

Guess you like

Origin blog.csdn.net/TianHW103/article/details/127680798