Implement a function with Matlab that equalizes grey-scale images based on their histogram. The input is a given grey level image; the output is the derived image with uniform intensity distribution.
时间: 2024-03-03 08:50:22 浏览: 101
Sure, here's an implementation of the function in MATLAB:
```matlab
function equalized_img = hist_equalization(img)
% Calculate histogram
[hist, bins] = imhist(img);
% Calculate cumulative distribution function (CDF)
cdf = cumsum(hist);
% Normalize CDF
cdf_normalized = cdf * max(hist) / max(cdf);
% Create lookup table
lut = interp1(bins, cdf_normalized, 0:255);
% Apply lookup table to image
equalized_img = uint8(lut(double(img)+1));
end
```
To use this function, simply pass in a grayscale image as the argument and it will return the equalized image. Here's an example of how to use it:
```matlab
% Load grayscale image
img = imread('image.jpg');
img_gray = rgb2gray(img);
% Apply histogram equalization
equalized_img = hist_equalization(img_gray);
% Display original and equalized images
subplot(1,2,1), imshow(img_gray), title('Original Image')
subplot(1,2,2), imshow(equalized_img), title('Equalized Image')
```
I hope this helps! Let me know if you have any questions.
阅读全文