[574]  1  function DataOut=im_levels(DataIn)


 2  %% set GUI config: no action defined


 3  DataOut=[]; %default output field


 4  if strcmp(DataIn,'*')


 5  return


 6  end


 7  %


 8  %parameters


 9  np=30


 10  %


 11  DataOut=DataIn;%default


 12 


 13  B=double(DataIn.A(:,:,1));


 14  windowsize=round(min(size(B,1),size(B,2))/20);


 15  windowsize=floor(windowsize/2)*2+1;


 16  ix=[1/2windowsize/2:1/2+windowsize/2];%


 17  %del=np/3;


 18  %fct=exp((ix/del).^2);


 19  fct2=cos(ix/((np1)/2)*pi/2);


 20  %Mfiltre=(ones(5,5)/5^2);


 21  %Mfiltre=fct2';


 22  Mfiltre=fct2'*fct2;


 23  Mfiltre=Mfiltre/(sum(sum(Mfiltre)));


 24 


 25  C=filter2(Mfiltre,B);


 26  C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);


 27  C(:,endwindowsize+1:end)=C(:,endwindowsize+1)*ones(1,windowsize);


 28  C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);


 29  C(endwindowsize+1:end,:)=ones(windowsize,1)*C(endwindowsize,:);


 30  C=tanh(B./(2*C));


 31  [n,c]=hist(reshape(C,1,[]),100);


 32  % figure;plot(c,n);


 33 


 34  [m,i]=max(n);


 35  c_max=c(i);


 36  [dummy,index]=sort(abs(cc(i)));


 37  n=n(index);


 38  c=c(index);


 39  i_select = find(cumsum(n)<0.95*sum(n));


 40  if isempty(i_select)


 41  i_select = 1:length(c);


 42  end


 43  c_select=c(i_select);


 44  n_select=n(i_select);


 45  cmin=min(c_select);


 46  cmax=max(c_select);


 47  C=(Ccmin)/(cmaxcmin)*256;


 48  DataOut.AA=uint8(C);


 49 


 50 


 51 


 52  DataOut.A=uint8(C);

