Apply new equalized histogram on the image matrix in matlab

时光总嘲笑我的痴心妄想 提交于 2019-12-13 04:23:56

问题


Suppose that based on my my previous question I have equalized the histogram of an image now the question is how to apply this new equalized histogram on the image?
I mean what is the algorithm to get the new image from the new equalized histogram?
I have seen a code about this in the net.
It is evident that the last for loops, shown in this photo, are for applying the equalized histogram on the image matrix.


But I don't understand the algorithm used.
Again note that it's a college assignment and I'm not permitted to use built-in functions available in the image processing toolbox.

回答1:


Well I found the algorithm for applying the new equalized histogram on the image matrix here.
The specific part of this web page that helped me is shown in this picture:


And the codes that I wrote for implementing this algorithm are in this link.
Note that lines 22 to 24 in the file "HistogramEqualization" implement the algorithm above for a gray scale image. And the code for an RGB one is the same except that it should be repeated for each color channel.


回答2:


  1. Create the histogram for the image.
  2. Calculate the cumulative distribution function histogram.
  3. Calculate the new values through the general histogram equalization formula.
  4. Assign new values for each gray value in the image.

    clc
    close all
    clear all
    %% HISTOGRAM EQULAIZER
    %%
    I1= imread ('C:\Users\sepideh\Pictures\dip\PC040311.jpg');
    zz=rgb2gray(I1);
    figure,subplot(1,2,1),imshow(zz), title('original image')
    subplot(1,2,2),imhist(zz),title('original image histogram')
    
    %% Calculating the CDF 
    hst=imhist(zz);
    j=1;
    cdff(1,1)=hst(1,1);
    for i=2:256
    cdff(i)=hst(i)+cdff(i-j); 
    end
    cdff1=cdff';
    cdf_min=min(cdff);
    [row col]=size(zz);
    mn=row*col;
    figure, plot(cdff), title('CDF of Image')
    %% calcuting new intensity
    for indx=1:length(cdff)
    h(indx)=round((cdff(indx)-cdf_min)/(mn-cdf_min)*255);
    
    end
    h1=h';
    figure,plot(h1), title('New value for General Histogram')
    
    %% EQULIZED IMAGE
    
    HIm=uint8(zeros(size(zz,1),size(zz,2)));
    
    for i=1:row;
    for j=1:col;
    HIm(i,j) = h((zz(i,j)+1));
    end
    end
    
    figure,subplot(1,2,1),imshow(HIm), title('Equlized Image')
    subplot(1,2,2),imhist(HIm) ,title('Equlized image histogram')
    


来源:https://stackoverflow.com/questions/17303335/apply-new-equalized-histogram-on-the-image-matrix-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!