Line | |
---|

1 | |
---|

2 | |
---|

3 | |
---|

4 | function C=levels(A) |
---|

5 | %whos A; |
---|

6 | B=double(A(:,:,1)); |
---|

7 | windowsize=round(min(size(B,1),size(B,2))/20); |
---|

8 | windowsize=floor(windowsize/2)*2+1; |
---|

9 | ix=[1/2-windowsize/2:-1/2+windowsize/2];% |
---|

10 | %del=np/3; |
---|

11 | %fct=exp(-(ix/del).^2); |
---|

12 | fct2=cos(ix/(windowsize-1)/2*pi/2); |
---|

13 | %Mfiltre=(ones(5,5)/5^2); |
---|

14 | %Mfiltre=fct2'; |
---|

15 | Mfiltre=fct2'*fct2; |
---|

16 | Mfiltre=Mfiltre/(sum(sum(Mfiltre))); |
---|

17 | |
---|

18 | C=filter2(Mfiltre,B); |
---|

19 | C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize); |
---|

20 | C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize); |
---|

21 | C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:); |
---|

22 | C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:); |
---|

23 | C=tanh(B./(2*C)); |
---|

24 | [n,c]=hist(reshape(C,1,[]),100); |
---|

25 | % figure;plot(c,n); |
---|

26 | |
---|

27 | [m,i]=max(n); |
---|

28 | c_max=c(i); |
---|

29 | [dummy,index]=sort(abs(c-c(i))); |
---|

30 | n=n(index); |
---|

31 | c=c(index); |
---|

32 | i_select = find(cumsum(n)<0.95*sum(n)); |
---|

33 | if isempty(i_select) |
---|

34 | i_select = 1:length(c); |
---|

35 | end |
---|

36 | c_select=c(i_select); |
---|

37 | n_select=n(i_select); |
---|

38 | cmin=min(c_select); |
---|

39 | cmax=max(c_select); |
---|

40 | C=(C-cmin)/(cmax-cmin)*256; |
---|

41 | C=uint8(C); |
---|

**Note:** See

TracBrowser
for help on using the repository browser.