2016-08-14 3 views
0

로컬 히스토그램 균등화를 수동으로 구현하고 있지만 결과가 만족스럽지 않습니다. 원하는 결과가 무엇인지 알 수 있습니다. 주어진 표현식에 따라 코드를 구현했지만 결과는 동일하지 않습니다. 여기 수동으로 로컬 히스토그램 균등화

Picture for problem

코드입니다 :

I=rgb2gray(imread('peppers.png')); 
if (isa(I,'uint8')) 
    I=double(I)/255; 
end 
if (size(I,3)==3) 
    I=(I(:,:,1)+I(:,:,2)+I(:,:,3))/3; % average the RGB channels 
end 
windowsize=17; 
% Create an empty array 
Ieq = zeros(size(I,1),size(I,2)); 
% Apply this over a NxN region around each pixel (N is odd) 
n = floor(windowsize/2); % <-- N is the half size of the region ie. [-N:N,-N:N] 
for r=1+n:size(I,1)-n 
    for c=1+n:size(I,2)-n 
    % -- INSERT YOUR CODE BELOW ------------------------------------------ 
    % NOTE: For pixels near the boundary, ensure the NxN neighbourhood is still 
    % inside the image (this means for pixels near the boundary the pixel may 
    % not be at the centre of the NxN neighbourhood). 
     if r-n <=1 
     fromrow=1; 
     torow=r+n; 
     else 
      fromrow=abs(r-n); 
      if n+r >= size(I,1) 
       torow=size(I,1); 
      else 
       torow=r+n; 
      end 
     end 
     if c-n <= 1 
      fromcol=1; 
      tocol=c+n; 
     else 
      fromcol=abs(c-n); 
      if c+n > size(I,2); 
       tocol=size(I,2); 
      else 
       tocol=c+n; 
      end 
     end 
     neighbour = I(fromrow:torow,fromcol:tocol); 
     lessoreq=neighbour(neighbour<=I(r,c)); 
     sumofval=sum(lessoreq); 
     pixval=sumofval/(size(neighbour,1)*size(neighbour,2)); 
     Ieq(r,c)=pixval; 
     % -- INSERT YOUR CODE ABOVE ------------------------------------------ 
    end 
    end 
    imshow(Ieq); 

답변

1

내가 "로컬 히스토그램 균등화"에 대한 하나 이상의 수식이있을 것 같다 - 당신은 당신의 익숙한 결과와 다른 공식을 구현했습니다.

은 여기 구현을 발견 http://angeljohnsy.blogspot.com/2011/06/local-histogram-equalization.html

내가 당신 입력을 사용하는 코드를 수정했습니다.
enter image description here

:

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

A=rgb2gray(imread('peppers.png')); 
figure,imshow(A); 
Img=A; 


%WINDOW SIZE 
M=17; 
N=17; 


mid_val=round((M*N)/2); 

%FIND THE NUMBER OF ROWS AND COLUMNS TO BE PADDED WITH ZERO 
in=0; 
for i=1:M 
    for j=1:N 
     in=in+1; 
     if(in==mid_val) 
      PadM=i-1; 
      PadN=j-1; 
      break; 
     end 
    end 
end 
%PADDING THE IMAGE WITH ZERO ON ALL SIDES 
B=padarray(A,[PadM,PadN]); 

for i= 1:size(B,1)-((PadM*2)+1) 

    for j=1:size(B,2)-((PadN*2)+1) 
     cdf=zeros(256,1); 
     inc=1; 
     for x=1:M 
      for y=1:N 
    %FIND THE MIDDLE ELEMENT IN THE WINDOW   
       if(inc==mid_val) 
        ele=B(i+x-1,j+y-1)+1; 
       end 
        pos=B(i+x-1,j+y-1)+1; 
        cdf(pos)=cdf(pos)+1; 
        inc=inc+1; 
      end 
     end 

     %COMPUTE THE CDF FOR THE VALUES IN THE WINDOW 
     for l=2:256 
      cdf(l)=cdf(l)+cdf(l-1); 
     end 
      Img(i,j)=round(cdf(ele)/(M*N)*255); 
    end 
end 
figure,imshow(Img); 
figure, 
subplot(2,1,1);title('Before Local Histogram Equalization'); imhist(A); 
subplot(2,1,2);title('After Local Histogram Equalization'); imhist(Img); 

결과는 당신이 원하는 것 같이 보인다

관련 문제