source: trunk/src/transform_field/im_levels.m @ 71

Last change on this file since 71 was 71, checked in by sommeria, 11 years ago

civ3D updated: introduction of image size
imadoc2struct: reding of image size from the xml file
set_object, view_field and related functions: improvement of projection object editing
mouse: possibility of adjusting the calibrations points with the mouse

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