⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp03.m

📁 HISTOGRAM EQUALIZATION
💻 M
字号:
% % % % % % % % % % % % % % % % % % % % % 
%  Program for HISTOGRAM EQUALIZATION  %
% % % % % % % % % % % % % % % % % % % % % 

clc; clear all; close all;

% Reading the image
I = imread('test_4.jpg');
% Here the dynamic range of the RGB components is [0 255] :)
% But the elements are in 'unit8' format; hence can't be processed directly
% :(

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%   dynamic range of pixel values [0 255]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Converting 'unit8' values to 'double' with dynamic range [0 255]
I_img = im2double(I) * 255;
% Seperating RGB Componants 
R = I_img(:,:,1);
G = I_img(:,:,2);
B = I_img(:,:,3);
% Converting to Gray Scale Image
A = round(0.299*R + 0.587*G + 0.114*B);
% Displaying original image and its gray scale version
figure;
subplot(1,2,1); imshow(I_img/255); title('Original Image');
subplot(1,2,2); imshow(A/255); title('Gray Scale Image');



[R C] = size(A);

%%%  (1) FINDING HISTOGRAM   %%%

h = zeros(1,256);

for x = 1:R
    for y = 1:C
        h(A(x,y) + 1) = h(A(x,y) + 1) + 1;
    end
end
figure;
r=1:1:256;
stem(r,h); 
title('Histogram of the Original Image');




%%% (2) HISTOGRAM EQUALIZATION  %%%


% Finding Probabality Density Function(PDF)
P = h /(R*C);

% Finding SDF
S= zeros(1,256);
for i = 1:1:256
    if i==1
        S(i) = P(i);   
    else
        S(i) = S(i-1) + P(i);
    end
end

S1 = S * 255;
S1 = round(S1);

% mapping
for x = 1:R
    for y = 1:C
       A1(x,y) = S1(A(x,y)+1);
    end
end

%displaying image
figure;
imshow(A1/255); title('Histogram Equalized Image');



%%%  (3) HISTOGRAM OF EQUALIZED IMAGE %%%

H = zeros(1,256);
[R C] = size(A1);
for x = 1:R
    for y = 1:C
        H(A1(x,y) + 1) = H(A1(x,y) + 1) + 1;
    end
end
figure;
r=1:1:256;
stem(r,H); title('Histogram of the new Image');



        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -