Histogram Equalization in MATLAB for Image Contrast Enhancement
发布时间: 2024-09-15 02:22:09 阅读量: 36 订阅数: 43
# 1. The Theoretical Foundation of Image Histogram Equalization
Image histogram equalization is a technique of image processing that enhances the contrast and visual effect of an image by adjusting the distribution of image pixels to make the histogram more uniform. The theoretical basis of histogram equalization lies in the fact that a uniformly distributed histogram represents a more balanced distribution of pixel values in the image, resulting in a clearer and higher contrast image.
The key steps of the histogram equalization algorithm are as follows:
1. Calculate the frequency distribution of each pixel value in the image to form the image histogram.
2. Accumulate the histogram to obtain the cumulative distribution function (CDF).
3. Normalize the cumulative distribution function to the range of [0, 1].
4. Apply the normalized cumulative distribution function to each pixel value to obtain equalized pixel values.
# 2. Implementation of Image Histogram Equalization in MATLAB
### 2.1 Introduction to the Histogram Equalization Algorithm
The histogram equalization algorithm adjusts the image histogram by redistributing pixel values to make it more uniform. The specific steps are as follows:
1. **Calculate the histogram of the original image:** Count the occurrence of each pixel value.
2. **Calculate the cumulative histogram:** Accumulate the occurrence of each pixel value to get the cumulative value.
3. **Normalize the cumulative histogram:** Divide each value in the cumulative histogram by the total number of pixels in the image to obtain the normalized cumulative histogram.
4. **Map the original pixel values:** Map each pixel value in the original image to the corresponding value in the normalized cumulative histogram.
### 2.2 Using the Histogram Equalization Function in MATLAB
MATLAB provides the `histeq` function to implement image histogram equalization. The syntax is as follows:
```matlab
J = histeq(I)
```
Where:
* `I`: Input image
* `J`: Equalized image
**Code Block:**
```matlab
% Read the original image
I = imread('image.jpg');
% Perform histogram equalization
J = histeq(I);
% Display the original image and the equalized image
subplot(1,2,1);
imshow(I);
title('Original Image');
subplot(1,2,2);
imshow(J);
title('Equalized Image');
```
**Line-by-Line Code Logic Interpretation:**
1. `I = imread('image.jpg')`: Read the original image.
2. `J = histeq(I)`: Perform histogram equalization on the original image.
3. `subplot(1,2,1)`: Create the first subplot for displaying the original image.
4. `imshow(I)`: Display the original image.
5. `title('Original Image')`: Set the title for the original image subplot.
6. `subplot(1,2,2)`: Create the second subplot for displaying the equalized image.
7. `imshow(J)`: Display the equalized image.
8. `title('Equalized Image')`: Set the title for the equalized image subplot.
# 3. Practical Applications of Image Histogram Equalization
### 3.1 Enhancing Image Contrast
#### 3.1.1 Contrast Issues with the Original Image
Image contrast refers to the degree of difference between the bright and dark areas in an image. High-contrast images have clear details and vibrant colors, while low-contrast images appear dull and uninteresting.
In some cases, the original image may have low contrast, which could be due to insufficient lighting conditions, overexposure, or underexposure. Images with low contrast are difficult to discern details and have poor visual effects.
#### 3.1.2 Improved Contrast after Histogram Equalization
Histogram equalization is a technique of image processing that can enhance the contrast of an image. It adjusts the distribution of pixel
0
0