source: trunk/src/series/relabel_i_j.m @ 177

Last change on this file since 177 was 128, checked in by sommeria, 14 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: 4.6 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=relabel_i_j(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 '_ij']);
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(curdir);
30basename_new=fullfile(path,[subdir_ima '_ij'],namebase);
31
32% read imadoc
33[XmlData,warntext]=imadoc2struct([basename '.xml']);
34nbfield1=size(XmlData.Time,1)
35nbfield2=size(XmlData.Time,2)
36
37answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
38test_level=isequal(answer,'Yes')
39
40%copy the xml file
41if exist([basename '.xml'],'file')
42    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
43    t=xmltree([basename_new '.xml']);
44   
45    %update information on the first image name in the series
46    uid_Heading=find(t,'ImaDoc/Heading');
47    if isempty(uid_Heading)
48        [t,uid_Heading]=add(t,1,'element','Heading');
49    end   
50    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
51    ImageName=name_generator(basename_new,num_i1(1),num_j1(1),'.png','_i_j');
52    [pth,ImageName]=fileparts(ImageName);
53    ImageName=[ImageName '.png']
54    if isempty(uid_ImageName)
55       [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
56    end
57    uid_value=children(t,uid_ImageName);
58    if isempty(uid_value)
59        t=add(t,uid_ImageName,'chardata',ImageName)%indicate  name of the first image, with ;png extension
60    else
61        t=set(t,uid_value(1),'value',ImageName)%indicate  name of the first image, with ;png extension
62    end 
63
64%     %add information about image transform
65%     [t,new_uid]=add(t,1,'element','ImageTransform');
66%     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
67%     [t]=add(t,NameFunction_uid,'chardata','sub_background');     
68%     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
69%     [t]=add(t,new_uid,'chardata',num2str(nbslice_i));
70%     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
71%     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
72%     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
73%     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
74    save(t,[basename_new '.xml'])
75end
76
77%main loop
78for ifile=1:nbfield1*nbfield2
79    update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
80    filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
81    num_j=mod(ifile-1,nbfield2)+1;
82    num_i=floor((ifile-1)/nbfield2)+1;
83    filename_new=name_generator(basename_new,num_i,num_j,'.png','_i_j');
84    if test_level
85        A=imread(filename);
86        C=levels(A);
87        imwrite(C,filename_new)
88    else
89        copyfile(filename,filename_new);
90    end   
91end
92
93
94
95function C=levels(A)
96%whos A;
97B=double(A(:,:,1));
98windowsize=round(min(size(B,1),size(B,2))/20);
99windowsize=floor(windowsize/2)*2+1;
100ix=[1/2-windowsize/2:-1/2+windowsize/2];%
101%del=np/3;
102%fct=exp(-(ix/del).^2);
103fct2=cos(ix/(windowsize-1)/2*pi/2);
104%Mfiltre=(ones(5,5)/5^2);
105%Mfiltre=fct2';
106Mfiltre=fct2'*fct2;
107Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
108
109C=filter2(Mfiltre,B);
110C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
111C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
112C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
113C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
114C=tanh(B./(2*C));
115[n,c]=hist(reshape(C,1,[]),100);
116% figure;plot(c,n);
117
118[m,i]=max(n);
119c_max=c(i);
120[dummy,index]=sort(abs(c-c(i)));
121n=n(index);
122c=c(index);
123i_select = find(cumsum(n)<0.95*sum(n));
124if isempty(i_select)
125    i_select = 1:length(c);
126end
127c_select=c(i_select);
128n_select=n(i_select);
129cmin=min(c_select);
130cmax=max(c_select);
131C=(C-cmin)/(cmax-cmin)*256;
132C=uint8(C);
Note: See TracBrowser for help on using the repository browser.