source: trunk/src/series/levels.m @ 412

Last change on this file since 412 was 347, checked in by gostiaux, 13 years ago

ima_levels in batch mode

File size: 985 bytes
Line 
1
2
3
4function C=levels(A)
5%whos A;
6B=double(A(:,:,1));
7windowsize=round(min(size(B,1),size(B,2))/20);
8windowsize=floor(windowsize/2)*2+1;
9ix=[1/2-windowsize/2:-1/2+windowsize/2];%
10%del=np/3;
11%fct=exp(-(ix/del).^2);
12fct2=cos(ix/(windowsize-1)/2*pi/2);
13%Mfiltre=(ones(5,5)/5^2);
14%Mfiltre=fct2';
15Mfiltre=fct2'*fct2;
16Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
17
18C=filter2(Mfiltre,B);
19C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
20C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
21C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
22C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
23C=tanh(B./(2*C));
24[n,c]=hist(reshape(C,1,[]),100);
25% figure;plot(c,n);
26
27[m,i]=max(n);
28c_max=c(i);
29[dummy,index]=sort(abs(c-c(i)));
30n=n(index);
31c=c(index);
32i_select = find(cumsum(n)<0.95*sum(n));
33if isempty(i_select)
34    i_select = 1:length(c);
35end
36c_select=c(i_select);
37n_select=n(i_select);
38cmin=min(c_select);
39cmax=max(c_select);
40C=(C-cmin)/(cmax-cmin)*256;
41C=uint8(C);
Note: See TracBrowser for help on using the repository browser.