Friday, 21 September 2012


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');

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

Related Posts :



16 comments:

  1. Thanks for the code, for the benifit of readers that want to have a bit wider view on Histogram Adjustments and Equalization in MATLAB.
    Checkout an excellent guide here with nice examples: http://imageprocessingblog.com/histogram-adjustments-in-matlab-part-ii-equalization/

    ReplyDelete
  2. Thanks for the code! Can you comment it please?

    ReplyDelete
  3. Thanks for the code! U are so good man

    ReplyDelete
  4. 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."

    ReplyDelete
  5. Yes, Please answer IraJane's question

    ReplyDelete
  6. 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;)

    ReplyDelete
  7. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
    Matlab Training in Chennai

    ReplyDelete
  8. I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
    Click here:
    python training in Bangalore
    Click here:
    python training in Bangalore

    ReplyDelete
  9. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    Devops Training in pune

    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Data Science course in rajaji nagar | Data Science with Python course in chenni
    Data Science course in electronic city | Data Science course in USA
    Data science course in pune | Data science course in kalyan nagar

    ReplyDelete
  12. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    AWS Interview Questions And Answers


    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    AWS Training in Pune | Best Amazon Web Services Training in Pune

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course

    ReplyDelete
  13. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  14. Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Java Training in Chennai & get to know everything you want to about software trainings.

    ReplyDelete