[Digital Image Processing] Matlab program for drawing grayscale image histogram and image histogram equalization to enhance image contrast

The program content is described as follows:

1. Display the histogram of the image
2. Histogram equalization is used to enhance the contrast of the image, and display the image before and after histogram equalization and the histogram of the image

The program code is as follows:

%Part 1
h=imread('cameraman.tif');
subplot(1,2,1),imshow(h);
subplot(1,2,2),imhist(h),
grid on,
ylabel('pixel count');
%Part 2
h=imread('cameraman.tif');
subplot(1,6,1),imshow(h);
g=histeq(h,40:60);
j=imadjust(h,[0.3,0.7],[]);
subplot(1,6,2),imshow(g);
subplot(1,6,5),imhist(g);
subplot(1,6,3),imshow(j);
subplot(1,6,6),imhist(j);
subplot(1,6,4),imhist(h),
grid on,
ylabel('pixel count');

The procedure principle is as follows:

part1, use the imread function to read the image cameraman.tif in the computer disk, use the function imshow to display the image in the image window, and then use the function imhist to obtain the histogram of the image and display it in the image window.

part2, respectively use the function histeq and the function imadjust to equalize the histogram of the image cameraman.tif to enhance the image contrast. We use the function imshow to display the original image, the image processed by the function histeq and the image processed by the function imadjust in the image window, and then use the function imhist to display the histograms of the three images in the image window.

The result of the program running is as follows:

part1:

 Figure 1: Image cameraman.tif and its histogram

part2:

 Figure 2: Original image, contrast-enhanced image, and histogram of each image

 Friends who see this, don’t forget to like it before leaving!

Follow bloggers to learn more about digital image processing!

Guess you like

Origin blog.csdn.net/qq_59049513/article/details/122585682