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

Last change on this file since 256 was 171, checked in by sommeria, 14 years ago

cleaning of documentation

File size: 4.0 KB
RevLine 
[171]1%'ima_levels': rescale the image intensity to reduce strong luminosity peaks
2%------------------------------------------------------------------------
3% function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
4%
5%OUTPUT
6% GUI_input=list of options in the GUI series.fig needed for the function
7%
8%INPUT:
9%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
10%num_i2:  series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
11%num_j1:  series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
12%num_j2:  series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
13%Series: Matlab structure containing information set by the series interface% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
[64]14%----------------------------------------------------------------------
15function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
16%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
17if ~exist('num_i1','var')
18    GUI_input={};
19    return %exit the function
20end
21
22%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
23hseries=guidata(Series.hseries);%handles of the GUI series
24WaitbarPos=get(hseries.waitbar_frame,'Position');
25%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27basename=fullfile(Series.RootPath,Series.RootFile) ;
28
29%create dir of the new images
30[dir_images,namebase]=fileparts(basename);
31[path,subdir_ima]=fileparts(dir_images);
[160]32dircur=pwd;
[64]33cd(path);
34mkdir([subdir_ima '_levels']);
[128]35  [xx,msg2] = fileattrib(subdir_ima,'+w','g'); %yield writing access (+w) to user group (g)
36if ~strcmp(msg2,'')
37    msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
38    cd(dircur)
39    return
40end
41cd(dircur);
[64]42basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
43
44% read imadoc
[160]45%[XmlData,warntext]=imadoc2struct([basename '.xml']);
46% nbfield1=size(XmlData.Time,1);
47% nbfield2=size(XmlData.Time,2);
[64]48
[160]49msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
[64]50
51%copy the xml file
52if exist([basename '.xml'],'file')
53    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
54end
55
56%main loop
[160]57nbfield=size(num_i1,2);
58nbfield2=size(num_i1,1);
[64]59for ifile=1:nbfield
60    update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
61    stopstate=get(hseries.RUN,'BusyAction');
62    if isequal(stopstate,'queue') % enable STOP command
63        for jfile=1:nbfield2
64            filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
65            filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
66            A=imread(filename);
67            C=levels(A);
68            imwrite(C,filename_new)
69        end
70    end
71end
72
73
74
75function C=levels(A)
76%whos A;
77B=double(A(:,:,1));
78windowsize=round(min(size(B,1),size(B,2))/20);
79windowsize=floor(windowsize/2)*2+1;
80ix=[1/2-windowsize/2:-1/2+windowsize/2];%
81%del=np/3;
82%fct=exp(-(ix/del).^2);
83fct2=cos(ix/(windowsize-1)/2*pi/2);
84%Mfiltre=(ones(5,5)/5^2);
85%Mfiltre=fct2';
86Mfiltre=fct2'*fct2;
87Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
88
[71]89C=filter2(Mfiltre,B);
[64]90C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
91C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
92C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
93C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
94C=tanh(B./(2*C));
95[n,c]=hist(reshape(C,1,[]),100);
96% figure;plot(c,n);
97
98[m,i]=max(n);
99c_max=c(i);
100[dummy,index]=sort(abs(c-c(i)));
101n=n(index);
102c=c(index);
103i_select = find(cumsum(n)<0.95*sum(n));
104if isempty(i_select)
105    i_select = 1:length(c);
106end
107c_select=c(i_select);
108n_select=n(i_select);
109cmin=min(c_select);
110cmax=max(c_select);
111C=(C-cmin)/(cmax-cmin)*256;
112C=uint8(C);
Note: See TracBrowser for help on using the repository browser.