histeq_c.asv

来自「Image enhancement in spatial domain, the」· ASV 代码 · 共 47 行

ASV
47
字号
%% Performing histogram equalization on Figure 3.8(a)
clear all
clc
I=imread('Fig0308(a)(fractured_spine).tif');
I=double(I);
big=max((max(I)));  %% Gives maximum value in the Image
[row col]=size(I);
C=row*col;          %% Gives the total number of pixels required
h=zeros(1,300);     %% Defining two arrays h and z to store the histogram values
z=zeros(1,300);
for n=1:1:row
    for m =1:1:col
        if I(n,m)==0    %% To ensure that the values of a are not zero
            I(n,m)=1;
        end
    end
end
%% The histogram of the original image
for n=1:1:row
    for m=1:1:col
        t=I(n,m);       %% Takes the value of the pixel 
        h(t)=h(t)+1;
    end
end
pdf=h/C;                %% Probability Function
cdf(1)=pdf(1);          %% So that we dont have the condition x(0) in the for loop below
for x=2:1:big
    cdf(x)=pdf(x)+ cdf(x-1);    %% Calculating the cdf
end
new=round(cdf*big);             %% new is the new gray level 
new=new+1;                      %% if new = 0; it is not to be taken in the loop 
%% The equalized image
for p=1:1:row
    for q=1:1:col
        temp=I(p,q);
        b(p,q)=new(temp);       %% b has the Equalized image
%% The equalized histogram         
        t=b(p,q);               %% Takes the value of the pixel
        z(t)=z(t)+1;
    end
end
b=b-1;                          %% Since we have initially incremented the value of n
%%  Plots of original image, equalized image with their histograms 
figure(1),imshow(uint8(I));
figure(2),bar(h);
figure(3),imshow(uint8(I));
figure(4),bar(z)

⌨️ 快捷键说明

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