function [output]=logcontrast(input)

%This function applies the log contrast operator used by the
%fuzzy threshold method

[rows,cols]=size(input);
output=zeros([rows,cols]);

%this line is only needed in matlab
input=double(input);
        
histo=histogram(input);

%a pixel value is considered significant if it occurs 
%more than 0.05 times the occuranceof the most occuring pixel
sig_factor=round(0.05*max(histo)); 

flag=0;
p_end=0;
for i=length(histo):-1:1 %for each pixel value
    if (histo(i)>sig_factor)&&(flag==0) %check if its significant
        flag=1;                         %if yes, define it as the end
        p_end=i
    end;
end;

c=255/(log(1+p_end));
for i=1:1:rows
    for j=1:1:cols
        output(i,j)=c*log(1+abs(input(i,j))); %apply log contrast
        
    end;
end;             

%this line is only needed in matlab
output=uint8(output);
