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

Last change on this file since 128 was 128, checked in by sommeria, 13 years ago

series: give writting access to the group for all subdirectories produced
uvmat.fig: change of vect and scalar frames (to be consistent with view_field)
uvmat: various cleaning
plot_field: various cleaning to improve axes definition and avoid blinking
geometry_calib: improved dispay of point coordiantes, improved link with dataview for REPLICATE.
struct2nc: repair bug , file was not closed.
cell2tab: cleaning
dataview: improve the browser
civ: solve pb of image naming

File size: 3.2 KB
Line 
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']);
23  [xx,msg2] = fileattrib(subdir_ima,'+w','g'); %yield writing access (+w) to user group (g)
24if ~strcmp(msg2,'')
25    msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
26    cd(dircur)
27    return
28end
29cd(dircur);
30cd(curdir);
31basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
32
33% read imadoc
34[XmlData,warntext]=imadoc2struct([basename '.xml']);
35nbfield1=size(XmlData.Time,1)
36nbfield2=size(XmlData.Time,2)
37
38answer=msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ')
39
40%copy the xml file
41if exist([basename '.xml'],'file')
42    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
43end
44
45%main loop
46nbfield=size(num_i1,2)
47nbfield2=size(num_i1,1)
48for ifile=1:nbfield
49    update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
50    stopstate=get(hseries.RUN,'BusyAction');
51    if isequal(stopstate,'queue') % enable STOP command
52        for jfile=1:nbfield2
53            filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
54            filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
55            A=imread(filename);
56            C=levels(A);
57            imwrite(C,filename_new)
58        end
59    end
60end
61
62
63
64function C=levels(A)
65%whos A;
66B=double(A(:,:,1));
67windowsize=round(min(size(B,1),size(B,2))/20);
68windowsize=floor(windowsize/2)*2+1;
69ix=[1/2-windowsize/2:-1/2+windowsize/2];%
70%del=np/3;
71%fct=exp(-(ix/del).^2);
72fct2=cos(ix/(windowsize-1)/2*pi/2);
73%Mfiltre=(ones(5,5)/5^2);
74%Mfiltre=fct2';
75Mfiltre=fct2'*fct2;
76Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
77
78C=filter2(Mfiltre,B);
79C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
80C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
81C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
82C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
83C=tanh(B./(2*C));
84[n,c]=hist(reshape(C,1,[]),100);
85% figure;plot(c,n);
86
87[m,i]=max(n);
88c_max=c(i);
89[dummy,index]=sort(abs(c-c(i)));
90n=n(index);
91c=c(index);
92i_select = find(cumsum(n)<0.95*sum(n));
93if isempty(i_select)
94    i_select = 1:length(c);
95end
96c_select=c(i_select);
97n_select=n(i_select);
98cmin=min(c_select);
99cmax=max(c_select);
100C=(C-cmin)/(cmax-cmin)*256;
101C=uint8(C);
Note: See TracBrowser for help on using the repository browser.