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

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

small bug repair and improvement of relabel_i_j

File size: 5.1 KB
Line 
1% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
2% (specific to RDvision system)
3%----------------------------------------------------------------------
4function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series)
5%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
6if ~exist('num_i1','var')
7    GUI_input={};
8    return %exit the function
9end
10
11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
12hseries=guidata(Series.hseries);%handles of the GUI series
13WaitbarPos=get(hseries.waitbar_frame,'Position');
14%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16%% PARAMETERS (for RDvision system)
17display('RDvision system')
18first_label=0 %image numbers start from 0
19errorfactor=2 %correct a factor of 2 in NbDk+1
20
21%% create dir of the new images
22basename=fullfile(Series.RootPath,Series.RootFile) ;
23[dir_images,namebase]=fileparts(basename);
24[path,subdir_ima]=fileparts(dir_images);
25newdir=fullfile(path,[subdir_ima '_ij']);
26mkdir(newdir);
27[xx,msg2] = fileattrib(newdir,'+w','g'); %yield writing access (+w) to user group (g)
28if ~strcmp(msg2,'')
29    msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
30    return
31end
32display(['relabelled images in the directory ' newdir])
33basename_new=fullfile(newdir,namebase);
34
35%% read imadoc
36[XmlData,warntext]=imadoc2struct([basename '.xml']);
37nbfield1=size(XmlData.Time,1)/errorfactor;
38nbfield2=size(XmlData.Time,2);
39set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
40set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process
41
42%% apply the image rescaling function 'level' (avoid bright particles)
43answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m');
44test_level=isequal(answer,'Yes');
45
46%% copy and adapt the xml file
47if exist([basename '.xml'],'file')
48    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
49    t=xmltree([basename_new '.xml']);
50   
51    %update information on the first image name in the series
52    uid_Heading=find(t,'ImaDoc/Heading');
53    if isempty(uid_Heading)
54        [t,uid_Heading]=add(t,1,'element','Heading');
55    end   
56    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
57    ImageName=name_generator(basename_new,1,1,'.png','_i_j');
58    [pth,ImageName]=fileparts(ImageName);
59    ImageName=[ImageName '.png']
60    if isempty(uid_ImageName)
61       [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
62    end
63    uid_value=children(t,uid_ImageName);
64    if isempty(uid_value)
65        t=add(t,uid_ImageName,'chardata',ImageName)%indicate  name of the first image, with ;png extension
66    else
67        t=set(t,uid_value(1),'value',ImageName)%indicate  name of the first image, with ;png extension
68    end 
69
70%     %add information about image transform
71%     [t,new_uid]=add(t,1,'element','ImageTransform');
72%     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
73%     [t]=add(t,NameFunction_uid,'chardata','sub_background');     
74%     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
75%     [t]=add(t,new_uid,'chardata',num2str(nbslice_i));
76%     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
77%     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
78%     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
79%     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
80    save(t,[basename_new '.xml'])
81end
82
83%% main loop
84for ifile=1:nbfield1*nbfield2
85    update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
86    filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
87    num_j=mod(ifile-1+first_label,nbfield2)+1;
88    num_i=floor((ifile-1+first_label)/nbfield2)+1;
89    filename_new=name_generator(basename_new,num_i,num_j,'.png','_i_j');
90    if test_level
91        A=imread(filename);
92        C=levels(A);
93        imwrite(C,filename_new)
94    else
95        copyfile(filename,filename_new);
96    end   
97end
98
99
100
101function C=levels(A)
102%whos A;
103B=double(A(:,:,1));
104windowsize=round(min(size(B,1),size(B,2))/20);
105windowsize=floor(windowsize/2)*2+1;
106ix=[1/2-windowsize/2:-1/2+windowsize/2];%
107%del=np/3;
108%fct=exp(-(ix/del).^2);
109fct2=cos(ix/(windowsize-1)/2*pi/2);
110%Mfiltre=(ones(5,5)/5^2);
111%Mfiltre=fct2';
112Mfiltre=fct2'*fct2;
113Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
114
115C=filter2(Mfiltre,B);
116C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
117C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
118C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
119C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
120C=tanh(B./(2*C));
121[n,c]=hist(reshape(C,1,[]),100);
122% figure;plot(c,n);
123
124[m,i]=max(n);
125c_max=c(i);
126[dummy,index]=sort(abs(c-c(i)));
127n=n(index);
128c=c(index);
129i_select = find(cumsum(n)<0.95*sum(n));
130if isempty(i_select)
131    i_select = 1:length(c);
132end
133c_select=c(i_select);
134n_select=n(i_select);
135cmin=min(c_select);
136cmax=max(c_select);
137C=(C-cmin)/(cmax-cmin)*256;
138C=uint8(C);
Note: See TracBrowser for help on using the repository browser.