source: trunk/src/transform_field/ima_levels.m @ 587

Last change on this file since 587 was 574, checked in by sommeria, 12 years ago

clean the transform fcts

File size: 1.3 KB
Line 
1function DataOut=im_levels(DataIn)
2%% set GUI config: no action defined
3DataOut=[];  %default  output field
4if strcmp(DataIn,'*')
5    return
6end
7%-----------------------------------------------
8%parameters
9np=30
10%---------------------------------------------------------
11DataOut=DataIn;%default
12
13B=double(DataIn.A(:,:,1));
14windowsize=round(min(size(B,1),size(B,2))/20);
15windowsize=floor(windowsize/2)*2+1;
16ix=[1/2-windowsize/2:-1/2+windowsize/2];%
17%del=np/3;
18%fct=exp(-(ix/del).^2);
19fct2=cos(ix/((np-1)/2)*pi/2);
20%Mfiltre=(ones(5,5)/5^2);
21%Mfiltre=fct2';
22Mfiltre=fct2'*fct2;
23Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
24
25C=filter2(Mfiltre,B);
26C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
27C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
28C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
29C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
30C=tanh(B./(2*C));
31[n,c]=hist(reshape(C,1,[]),100);
32% figure;plot(c,n);
33
34[m,i]=max(n);
35c_max=c(i);
36[dummy,index]=sort(abs(c-c(i)));
37n=n(index);
38c=c(index);
39i_select = find(cumsum(n)<0.95*sum(n));
40if isempty(i_select)
41    i_select = 1:length(c);
42end
43c_select=c(i_select);
44n_select=n(i_select);
45cmin=min(c_select);
46cmax=max(c_select);
47C=(C-cmin)/(cmax-cmin)*256;
48DataOut.AA=uint8(C);
49
50
51
52DataOut.A=uint8(C);
Note: See TracBrowser for help on using the repository browser.