source: trunk/src/series/ima2vol.m @ 865

Last change on this file since 865 was 810, checked in by g7moreau, 10 years ago
  • Add license
File size: 5.9 KB
RevLine 
[171]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%
[41]15%----------------------------------------------------------------------
[810]16
17%=======================================================================
18% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF 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
[41]35function 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)
37if ~exist('num_i1','var')
38    GUI_input={};
39    return %exit the function
40end
41
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
43hseries=guidata(Series.hseries);%handles of the GUI series
44WaitbarPos=get(hseries.waitbar_frame,'Position');
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47basename=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);
52curdir=pwd;
53cd(path);
[72]54mkdir([subdir_ima '_vol']);
[41]55cd(curdir);
[72]56basename_new=fullfile(path,[subdir_ima '_vol'],namebase);
[41]57
58% read imadoc
59[XmlData,warntext]=imadoc2struct([basename '.xml']);
60nbfield1=size(XmlData.Time,1)
61nbfield2=size(XmlData.Time,2)
62
63answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
64test_level=isequal(answer,'Yes')
65
66%copy the xml file
67if 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'])
90end
91
92%main loop
93 vol=[];
[73]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
[41]116
117
118
[73]119function C=levels(A,bitdepth)
[41]120%whos A;
121B=double(A(:,:,1));
122windowsize=round(min(size(B,1),size(B,2))/20);
123windowsize=floor(windowsize/2)*2+1;
124ix=[1/2-windowsize/2:-1/2+windowsize/2];%
125%del=np/3;
126%fct=exp(-(ix/del).^2);
127fct2=cos(ix/(windowsize-1)/2*pi/2);
128%Mfiltre=(ones(5,5)/5^2);
129%Mfiltre=fct2';
130Mfiltre=fct2'*fct2;
131Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
132
[72]133C=filter2(Mfiltre,B);
[41]134C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
135C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
136C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
137C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
138C=tanh(B./(2*C));
139[n,c]=hist(reshape(C,1,[]),100);
140% figure;plot(c,n);
141
142[m,i]=max(n);
143c_max=c(i);
144[dummy,index]=sort(abs(c-c(i)));
145n=n(index);
146c=c(index);
147i_select = find(cumsum(n)<0.95*sum(n));
148if isempty(i_select)
149    i_select = 1:length(c);
150end
151c_select=c(i_select);
152n_select=n(i_select);
153cmin=min(c_select);
154cmax=max(c_select);
[73]155if isequal(bitdepth,16)
156    C=((C-cmin)/(cmax-cmin))*256*256;
157    C=uint16(C);
158else
159    C=((C-cmin)/(cmax-cmin))*256;
160    C=uint8(C);
[810]161end
Note: See TracBrowser for help on using the repository browser.