Vous êtes sur la page 1sur 4

8/26/2014

Matlab code: Histogram equalization without using histeq function | IMAGE PROCESSING

IMAGE PROCESSING
Follow
+ 176

Image Processing
Like

2,474 people like Image Processing.

Facebook social plugin

Its Totally Random

MATLAB CODE:

GIm=imread('tire.tif');

numofpixels=size(GIm,1)*size(GIm,2);

figure,imshow(GIm);

Subscribe Now:
Subscribe in a reader

YOU ARE HERE

title('Original Image');

HIm=uint8(zeros(size(GIm,1),size(GIm,2)));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);

http://angeljohnsy.blogspot.com/2011/04/matlab-code-histogram-equalization.html

2/8

8/26/2014

Matlab code: Histogram equalization without using histeq function | IMAGE PROCESSING

Live Traffic Feed


%freq counts the occurrence of each pixel value.
%The probability of each occurrence is calculated by probf.

for i=1:size(GIm,1)
for j=1:size(GIm,2)
value=GIm(i,j);
freq(value+1)=freq(value+1)+1;
probf(value+1)=freq(value+1)/numofpixels;
end
end

sum=0;
no_bins=255;

%The cumulative distribution probability is calculated.


for i=1:size(probf)
sum=sum+freq(i);
cum(i)=sum;
probc(i)=cum(i)/numofpixels;
output(i)=round(probc(i)*no_bins);
end
for i=1:size(GIm,1)
for j=1:size(GIm,2)

A visitor from Chittagong,


Bangladesh viewed Sobel
edge detection | IMAGE
PROCESSING
4 mins ago
A
visitor from Evanston,
United States viewed
MATLAB CODE:Local
Histogram
equalization...
A
visitor from
Lugano, 5
mins
ago viewed Sobel
Switzerland
edge detection | IMAGE
PROCESSING
6 mins
ago
A
visitor from Ipoh,
Malaysia
viewed Find Area, Perimeter,
Centroid, Equivdia... 9 mins
A visitor from Dayton, United
ago
States viewed Image Erosion
without using MATLAB
funct...
minsIslamabad,
ago
A visitor10from
Pakistan viewed FACE
DETECTION - MATLAB
CODE
PRO...
10
A
visitor| IMAGE
from India
viewed
mins ago
TILE
SWAPPING GAME |
IMAGE PROCESSING 27
A visitor from Thanjavur, India
mins ago
viewed Bit-Plane Slicing |
IMAGE PROCESSING 35
A visitor from Petaling Jaya,
mins ago
Malaysia viewed Sobel edge
detection | IMAGE
PROCESSING
40 mins ago
A
visitor from Barcelona,
Spain viewed Image
Sharpening using second order
A visitor from Kharagpur,
deri... 44 mins ago
India viewed Sobel edge
detection | IMAGE
A visitor from Salai, India
PROCESSING 47 mins ago
viewed
MATLAB
Real-time
view Menu

HIm(i,j)=output(GIm(i,j)+1);
end
end
figure,imshow(HIm);

TAGS

title('Histogram equalization');

GUI Components in
MATLAB Removing
Image noise Image
Conversion
Photoshop
effects in MATLAB Edge
detection
MATLAB
BUILT_IN
FUNCTIONS
Morphological
Image
Processing Array functions in
MATLAB Video Processing Object
Identification
Optical
illusion
Shapes Templates Files Histogram
equalization

Image

Compression

Image Arithmetic Image Geometry

Followers

%The result is shown in the form of a table

http://angeljohnsy.blogspot.com/2011/04/matlab-code-histogram-equalization.html

3/8

8/26/2014

Matlab code: Histogram equalization without using histeq function | IMAGE PROCESSING

figure('Position',get(0,'screensize'));

Join this site


w ith Google Friend Connect

dat=cell(256,6);

Members (50) More


for i=1:256
dat(i,:)={i,freq(i),probf(i),cum(i),probc(i),output(i)};
end

columnname =

{'Bin', 'Histogram', 'Probability', 'Cumulative histogram','CDF','Output'};

columnformat = {'numeric', 'numeric', 'numeric', 'numeric', 'numeric','numeric'};

Already a member? Sign in

columneditable = [false false false false false false];


t = uitable('Units','normalized','Position',...
[0.1 0.1 0.4 0.9], 'Data', dat,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'RowName',[]);
subplot(2,2,2); bar(GIm);
title('Before Histogram equalization');
subplot(2,2,4); bar(HIm);
title('After Histogram equalization');

To find the histogram of an Image:


http://angeljohnsy.blogspot.com/2011/06/histogram-of-image.html

Local histogram equalization of an


Image: http://angeljohnsy.blogspot.com/2011/06/local-histogram-equalization.html

Here is a simple Version of Histogram Equalization MATLAB CODE:

http://angeljohnsy.blogspot.com/2011/04/matlab-code-histogram-equalization.html

4/8

8/26/2014

Matlab code: Histogram equalization without using histeq function | IMAGE PROCESSING

%Read a grayscale Image or a matrix mxn


A=imread('tire.tif');
figure,imshow(A);
%Specify the bin range[0 255]
bin=255;
%Find the histogram of the image.
Val=reshape(A,[],1);
Val=double(Val);
I=hist(Val,0:bin);
%Divide the result by number of pixels
Output=I/numel(A);
%Calculate the Cumlative sum
CSum=cumsum(Output);

%Perform the transformation S=T(R) where S and R in the range [ 0 1]


HIm=CSum(A+1);
%Convert the image into uint8
HIm=uint8(HIm*bin);
figure,imshow(HIm);

Like "IMAGE PROCESSING" page

Labels: Histogram equalization


Your Reactions:

Useful (5)

Interesting (0)

Not bad (0)

:-( (0)

21 comments:
Anonymous said...
its nice that this space provides output too..and most importantly..the code
works!!unlike most of the other sites!
-thank u soo much for this code.
September 26, 2011 at 7:53 PM
su_ng said...
good, very good
December 12, 2011 at 9:10 PM
cool_images said...
its last part is not working 3rd fig does not plot.ERROR::::bar must be 2 -D;
help me out
Thanx in advance...
December 14, 2011 at 11:50 PM
raj kumar said...

http://angeljohnsy.blogspot.com/2011/04/matlab-code-histogram-equalization.html

5/8

Vous aimerez peut-être aussi