MATLAB Program to apply Histogram Equalization on image
Code
clear all
clc
I=imread(‘cameraman.tif’);
I=double(I);
maximum_value=max((max(I)));
[row col]=size(I);
c=row*col;
h=zeros(1,300);
z=zeros(1,300);
for n=1:row
for m=1:col
if I(n,m) == 0
I(n,m)=1;
end
end
end
for n=1:row
for m=1:col
t = I(n,m);
h(t) = h(t) + 1;
end
end
pdf = h/c;
cdf(1) = pdf(1);
for x=2:maximum_value
cdf(x) = pdf(x) + cdf(x-1);
end
new = round(cdf * maximum_value);
new= new + 1;
for p=1:row
for q=1:col
temp=I(p,q);
b(p,q)=new(temp);
t=b(p,q);
z(t)=z(t)+1;
end
end
b=b-1;
subplot(2,2,1), imshow(uint8(I)) , title(‘ Image1’);
clc
I=imread(‘cameraman.tif’);
I=double(I);
maximum_value=max((max(I)));
[row col]=size(I);
c=row*col;
h=zeros(1,300);
z=zeros(1,300);
for n=1:row
for m=1:col
if I(n,m) == 0
I(n,m)=1;
end
end
end
for n=1:row
for m=1:col
t = I(n,m);
h(t) = h(t) + 1;
end
end
pdf = h/c;
cdf(1) = pdf(1);
for x=2:maximum_value
cdf(x) = pdf(x) + cdf(x-1);
end
new = round(cdf * maximum_value);
new= new + 1;
for p=1:row
for q=1:col
temp=I(p,q);
b(p,q)=new(temp);
t=b(p,q);
z(t)=z(t)+1;
end
end
b=b-1;
subplot(2,2,1), imshow(uint8(I)) , title(‘ Image1’);
subplot(2,2,2), bar(h) , title(‘Histogram of d Orig. Image’);
subplot(2,2,3), imshow(uint8(b)) , title(‘Image2’);
subplot(2,2,4),bar(z) , title(‘Histogram Equalisation of image2′);
Output Of An Histogram Equalization
Thanks for the code! Can you comment it please?
Thanks dear. much needed
Thanks for the code! U are so good man
pdf= (image1/ Total_numberOfPixels); %normalized histogram
cdf(1)= pdf(1);
for k=2:min_value
cdf(k)= pdf(k)+ cdf(k-1); %error at cdf
end
kindly, tell me how to remove this error.
"The size of the indicated variable or array appears to be changing with each loop iteration. Commonly, this message appears because an array is growing by assignment or concatenation. Growing an array by assignment or concatenation can be expensive. For large arrays, MATLAB must allocate a new block of memory and copy the older array contents to the new array as it makes each assignment."
Yes, Please answer IraJane's question
hi guys:)
i copied above code in matlab for a jpg format image, but i got this error
Undefined function 'colon' for input arguments of type 'double' and attributes
'full 3d real'.
Error in f044 (line 24)
for x=2:maximum_value
in which I have saved my code as fo44.m
thankfull for any helping;)