source: trunk/src/series/ima_levels.m @ 71

Last change on this file since 71 was 71, checked in by sommeria, 14 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: 2.9 KB
RevLine 
[64]1% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
2%----------------------------------------------------------------------
3function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
4%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
5if ~exist('num_i1','var')
6    GUI_input={};
7    return %exit the function
8end
9
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
11hseries=guidata(Series.hseries);%handles of the GUI series
12WaitbarPos=get(hseries.waitbar_frame,'Position');
13%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15basename=fullfile(Series.RootPath,Series.RootFile) ;
16
17%create dir of the new images
18[dir_images,namebase]=fileparts(basename);
19[path,subdir_ima]=fileparts(dir_images);
20curdir=pwd;
21cd(path);
22mkdir([subdir_ima '_levels']);
23cd(curdir);
24basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
25
26% read imadoc
27[XmlData,warntext]=imadoc2struct([basename '.xml']);
28nbfield1=size(XmlData.Time,1)
29nbfield2=size(XmlData.Time,2)
30
31answer=msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ')
32
33%copy the xml file
34if exist([basename '.xml'],'file')
35    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
36end
37
38%main loop
39nbfield=size(num_i1,2)
40nbfield2=size(num_i1,1)
41for ifile=1:nbfield
42    update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
43    stopstate=get(hseries.RUN,'BusyAction');
44    if isequal(stopstate,'queue') % enable STOP command
45        for jfile=1:nbfield2
46            filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
47            filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
48            A=imread(filename);
49            C=levels(A);
50            imwrite(C,filename_new)
51        end
52    end
53end
54
55
56
57function C=levels(A)
58%whos A;
59B=double(A(:,:,1));
60windowsize=round(min(size(B,1),size(B,2))/20);
61windowsize=floor(windowsize/2)*2+1;
62ix=[1/2-windowsize/2:-1/2+windowsize/2];%
63%del=np/3;
64%fct=exp(-(ix/del).^2);
65fct2=cos(ix/(windowsize-1)/2*pi/2);
66%Mfiltre=(ones(5,5)/5^2);
67%Mfiltre=fct2';
68Mfiltre=fct2'*fct2;
69Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
70
[71]71C=filter2(Mfiltre,B);
[64]72C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
73C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
74C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
75C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
76C=tanh(B./(2*C));
77[n,c]=hist(reshape(C,1,[]),100);
78% figure;plot(c,n);
79
80[m,i]=max(n);
81c_max=c(i);
82[dummy,index]=sort(abs(c-c(i)));
83n=n(index);
84c=c(index);
85i_select = find(cumsum(n)<0.95*sum(n));
86if isempty(i_select)
87    i_select = 1:length(c);
88end
89c_select=c(i_select);
90n_select=n(i_select);
91cmin=min(c_select);
92cmax=max(c_select);
93C=(C-cmin)/(cmax-cmin)*256;
94C=uint8(C);
Note: See TracBrowser for help on using the repository browser.