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 | %----------------------------------------------------------------------
|
---|
4 | function 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)
|
---|
6 | if ~exist('num_i1','var')
|
---|
7 | GUI_input={};
|
---|
8 | return %exit the function
|
---|
9 | end
|
---|
10 |
|
---|
11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
|
---|
12 | hseries=guidata(Series.hseries);%handles of the GUI series
|
---|
13 | WaitbarPos=get(hseries.waitbar_frame,'Position');
|
---|
14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
15 |
|
---|
16 | %% PARAMETERS (for RDvision system)
|
---|
17 | display('RDvision system')
|
---|
18 | first_label=0 %image numbers start from 0
|
---|
19 | errorfactor=2 %correct a factor of 2 in NbDk+1
|
---|
20 |
|
---|
21 | %% create dir of the new images
|
---|
22 | basename=fullfile(Series.RootPath,Series.RootFile) ;
|
---|
23 | [dir_images,namebase]=fileparts(basename);
|
---|
24 | [path,subdir_ima]=fileparts(dir_images);
|
---|
25 | newdir=fullfile(path,[subdir_ima '_ij']);
|
---|
26 | mkdir(newdir);
|
---|
27 | [xx,msg2] = fileattrib(newdir,'+w','g'); %yield writing access (+w) to user group (g)
|
---|
28 | if ~strcmp(msg2,'')
|
---|
29 | msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
|
---|
30 | return
|
---|
31 | end
|
---|
32 | display(['relabelled images in the directory ' newdir])
|
---|
33 | basename_new=fullfile(newdir,namebase);
|
---|
34 |
|
---|
35 | %% read imadoc
|
---|
36 | [XmlData,warntext]=imadoc2struct([basename '.xml']);
|
---|
37 | nbfield1=size(XmlData.Time,1)/errorfactor;
|
---|
38 | nbfield2=size(XmlData.Time,2);
|
---|
39 | set(hseries.first_i,'String',num2str(first_label))% display the first image in the process
|
---|
40 | set(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)
|
---|
43 | answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m');
|
---|
44 | test_level=isequal(answer,'Yes');
|
---|
45 |
|
---|
46 | %% copy and adapt the xml file
|
---|
47 | if 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'])
|
---|
81 | end
|
---|
82 |
|
---|
83 | %% main loop
|
---|
84 | for 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
|
---|
97 | end
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | function C=levels(A)
|
---|
102 | %whos A;
|
---|
103 | B=double(A(:,:,1));
|
---|
104 | windowsize=round(min(size(B,1),size(B,2))/20);
|
---|
105 | windowsize=floor(windowsize/2)*2+1;
|
---|
106 | ix=[1/2-windowsize/2:-1/2+windowsize/2];%
|
---|
107 | %del=np/3;
|
---|
108 | %fct=exp(-(ix/del).^2);
|
---|
109 | fct2=cos(ix/(windowsize-1)/2*pi/2);
|
---|
110 | %Mfiltre=(ones(5,5)/5^2);
|
---|
111 | %Mfiltre=fct2';
|
---|
112 | Mfiltre=fct2'*fct2;
|
---|
113 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
|
---|
114 |
|
---|
115 | C=filter2(Mfiltre,B);
|
---|
116 | C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
|
---|
117 | C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
|
---|
118 | C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
|
---|
119 | C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
|
---|
120 | C=tanh(B./(2*C));
|
---|
121 | [n,c]=hist(reshape(C,1,[]),100);
|
---|
122 | % figure;plot(c,n);
|
---|
123 |
|
---|
124 | [m,i]=max(n);
|
---|
125 | c_max=c(i);
|
---|
126 | [dummy,index]=sort(abs(c-c(i)));
|
---|
127 | n=n(index);
|
---|
128 | c=c(index);
|
---|
129 | i_select = find(cumsum(n)<0.95*sum(n));
|
---|
130 | if isempty(i_select)
|
---|
131 | i_select = 1:length(c);
|
---|
132 | end
|
---|
133 | c_select=c(i_select);
|
---|
134 | n_select=n(i_select);
|
---|
135 | cmin=min(c_select);
|
---|
136 | cmax=max(c_select);
|
---|
137 | C=(C-cmin)/(cmax-cmin)*256;
|
---|
138 | C=uint8(C);
|
---|