1 | %'ima2vol': concatene image series to form a 'volume' image .vol used for 3D PIV
|
---|
2 | %------------------------------------------------------------------------
|
---|
3 | % function GUI_input=ima2vol(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
|
---|
14 | %
|
---|
15 | %----------------------------------------------------------------------
|
---|
16 |
|
---|
17 | %=======================================================================
|
---|
18 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
19 | % http://www.legi.grenoble-inp.fr
|
---|
20 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
21 | %
|
---|
22 | % This file is part of the toolbox UVMAT.
|
---|
23 | %
|
---|
24 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
25 | % it under the terms of the GNU General Public License as published
|
---|
26 | % by the Free Software Foundation; either version 2 of the license,
|
---|
27 | % or (at your option) any later version.
|
---|
28 | %
|
---|
29 | % UVMAT is distributed in the hope that it will be useful,
|
---|
30 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
31 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
32 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
33 | %=======================================================================
|
---|
34 |
|
---|
35 | function GUI_input=ima2vol(num_i1,num_i2,num_j1,num_j2,Series)
|
---|
36 | %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
|
---|
37 | if ~exist('num_i1','var')
|
---|
38 | GUI_input={};
|
---|
39 | return %exit the function
|
---|
40 | end
|
---|
41 |
|
---|
42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
|
---|
43 | hseries=guidata(Series.hseries);%handles of the GUI series
|
---|
44 | WaitbarPos=get(hseries.waitbar_frame,'Position');
|
---|
45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
46 |
|
---|
47 | basename=fullfile(Series.RootPath,Series.RootFile) ;
|
---|
48 |
|
---|
49 | %create dir of the new images
|
---|
50 | [dir_images,namebase]=fileparts(basename);
|
---|
51 | [path,subdir_ima]=fileparts(dir_images);
|
---|
52 | curdir=pwd;
|
---|
53 | cd(path);
|
---|
54 | mkdir([subdir_ima '_vol']);
|
---|
55 | cd(curdir);
|
---|
56 | basename_new=fullfile(path,[subdir_ima '_vol'],namebase);
|
---|
57 |
|
---|
58 | % read imadoc
|
---|
59 | [XmlData,warntext]=imadoc2struct([basename '.xml']);
|
---|
60 | nbfield1=size(XmlData.Time,1)
|
---|
61 | nbfield2=size(XmlData.Time,2)
|
---|
62 |
|
---|
63 | answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
|
---|
64 | test_level=isequal(answer,'Yes')
|
---|
65 |
|
---|
66 | %copy the xml file
|
---|
67 | if exist([basename '.xml'],'file')
|
---|
68 | copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
|
---|
69 | t=xmltree([basename_new '.xml']);
|
---|
70 |
|
---|
71 | %update information on the first image name in the series
|
---|
72 | uid_Heading=find(t,'ImaDoc/Heading');
|
---|
73 | if isempty(uid_Heading)
|
---|
74 | [t,uid_Heading]=add(t,1,'element','Heading');
|
---|
75 | end
|
---|
76 | uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
|
---|
77 | ImageName=name_generator(basename_new,num_i1(1),num_j1(1),'.png','_i_j');
|
---|
78 | [pth,ImageName]=fileparts(ImageName);
|
---|
79 | ImageName=[ImageName '.png']
|
---|
80 | if isempty(uid_ImageName)
|
---|
81 | [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
|
---|
82 | end
|
---|
83 | uid_value=children(t,uid_ImageName);
|
---|
84 | if isempty(uid_value)
|
---|
85 | t=add(t,uid_ImageName,'chardata',ImageName)%indicate name of the first image, with ;png extension
|
---|
86 | else
|
---|
87 | t=set(t,uid_value(1),'value',ImageName)%indicate name of the first image, with ;png extension
|
---|
88 | end
|
---|
89 | save(t,[basename_new '.xml'])
|
---|
90 | end
|
---|
91 |
|
---|
92 | %main loop
|
---|
93 | vol=[];
|
---|
94 | for ifile=1:nbfield1*nbfield2
|
---|
95 | update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
|
---|
96 | stopstate=get(hseries.RUN,'BusyAction');
|
---|
97 | if isequal(stopstate,'queue') % enable STOP command
|
---|
98 | filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
|
---|
99 | num_j=mod(ifile-1,nbfield2)+1;
|
---|
100 | num_i=floor((ifile-1)/nbfield2)+1;
|
---|
101 | A=imread(filename);
|
---|
102 | Atype=class(A);
|
---|
103 | if test_level
|
---|
104 | A=levels(A,16);
|
---|
105 | display(num2str(num_i))
|
---|
106 | end
|
---|
107 | vol=[vol;A];%concacene along y
|
---|
108 | if num_j==nbfield2
|
---|
109 | filename_new=name_generator(basename_new,num_i,1,'.vol','_i');
|
---|
110 | imwrite(vol,filename_new,'png','BitDepth',16)% WRITE IN 16 bits: needed for the current version of civ3C3D
|
---|
111 | display([filename_new 'written (16bits image)'])
|
---|
112 | vol=[];
|
---|
113 | end
|
---|
114 | end
|
---|
115 | end
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 | function C=levels(A,bitdepth)
|
---|
120 | %whos A;
|
---|
121 | B=double(A(:,:,1));
|
---|
122 | windowsize=round(min(size(B,1),size(B,2))/20);
|
---|
123 | windowsize=floor(windowsize/2)*2+1;
|
---|
124 | ix=[1/2-windowsize/2:-1/2+windowsize/2];%
|
---|
125 | %del=np/3;
|
---|
126 | %fct=exp(-(ix/del).^2);
|
---|
127 | fct2=cos(ix/(windowsize-1)/2*pi/2);
|
---|
128 | %Mfiltre=(ones(5,5)/5^2);
|
---|
129 | %Mfiltre=fct2';
|
---|
130 | Mfiltre=fct2'*fct2;
|
---|
131 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
|
---|
132 |
|
---|
133 | C=filter2(Mfiltre,B);
|
---|
134 | C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
|
---|
135 | C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
|
---|
136 | C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
|
---|
137 | C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
|
---|
138 | C=tanh(B./(2*C));
|
---|
139 | [n,c]=hist(reshape(C,1,[]),100);
|
---|
140 | % figure;plot(c,n);
|
---|
141 |
|
---|
142 | [m,i]=max(n);
|
---|
143 | c_max=c(i);
|
---|
144 | [dummy,index]=sort(abs(c-c(i)));
|
---|
145 | n=n(index);
|
---|
146 | c=c(index);
|
---|
147 | i_select = find(cumsum(n)<0.95*sum(n));
|
---|
148 | if isempty(i_select)
|
---|
149 | i_select = 1:length(c);
|
---|
150 | end
|
---|
151 | c_select=c(i_select);
|
---|
152 | n_select=n(i_select);
|
---|
153 | cmin=min(c_select);
|
---|
154 | cmax=max(c_select);
|
---|
155 | if isequal(bitdepth,16)
|
---|
156 | C=((C-cmin)/(cmax-cmin))*256*256;
|
---|
157 | C=uint16(C);
|
---|
158 | else
|
---|
159 | C=((C-cmin)/(cmax-cmin))*256;
|
---|
160 | C=uint8(C);
|
---|
161 | end
|
---|