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

Last change on this file since 577 was 171, checked in by sommeria, 14 years ago

cleaning of documentation

File size: 5.0 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%----------------------------------------------------------------------
16function GUI_input=ima2vol(num_i1,num_i2,num_j1,num_j2,Series)
17%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
18if ~exist('num_i1','var')
19    GUI_input={};
20    return %exit the function
21end
22
23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
24hseries=guidata(Series.hseries);%handles of the GUI series
25WaitbarPos=get(hseries.waitbar_frame,'Position');
26%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28basename=fullfile(Series.RootPath,Series.RootFile) ;
29
30%create dir of the new images
31[dir_images,namebase]=fileparts(basename);
32[path,subdir_ima]=fileparts(dir_images);
33curdir=pwd;
34cd(path);
[72]35mkdir([subdir_ima '_vol']);
[41]36cd(curdir);
[72]37basename_new=fullfile(path,[subdir_ima '_vol'],namebase);
[41]38
39% read imadoc
40[XmlData,warntext]=imadoc2struct([basename '.xml']);
41nbfield1=size(XmlData.Time,1)
42nbfield2=size(XmlData.Time,2)
43
44answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
45test_level=isequal(answer,'Yes')
46
47%copy the xml file
48if exist([basename '.xml'],'file')
49    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
50    t=xmltree([basename_new '.xml']);
51   
52    %update information on the first image name in the series
53    uid_Heading=find(t,'ImaDoc/Heading');
54    if isempty(uid_Heading)
55        [t,uid_Heading]=add(t,1,'element','Heading');
56    end   
57    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
58    ImageName=name_generator(basename_new,num_i1(1),num_j1(1),'.png','_i_j');
59    [pth,ImageName]=fileparts(ImageName);
60    ImageName=[ImageName '.png']
61    if isempty(uid_ImageName)
62       [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
63    end
64    uid_value=children(t,uid_ImageName);
65    if isempty(uid_value)
66        t=add(t,uid_ImageName,'chardata',ImageName)%indicate  name of the first image, with ;png extension
67    else
68        t=set(t,uid_value(1),'value',ImageName)%indicate  name of the first image, with ;png extension
69    end 
70    save(t,[basename_new '.xml'])
71end
72
73%main loop
74 vol=[];
[73]75 for ifile=1:nbfield1*nbfield2
76     update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
77     stopstate=get(hseries.RUN,'BusyAction');
78     if isequal(stopstate,'queue') % enable STOP command
79         filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
80         num_j=mod(ifile-1,nbfield2)+1;
81         num_i=floor((ifile-1)/nbfield2)+1;
82         A=imread(filename);
83         Atype=class(A);
84         if test_level
85             A=levels(A,16);
86             display(num2str(num_i))
87         end
88         vol=[vol;A];%concacene along y
89         if num_j==nbfield2
90             filename_new=name_generator(basename_new,num_i,1,'.vol','_i');
91             imwrite(vol,filename_new,'png','BitDepth',16)% WRITE IN 16 bits: needed for the current version of civ3C3D
92             display([filename_new 'written (16bits image)'])
93             vol=[];
94         end
95     end
96 end
[41]97
98
99
[73]100function C=levels(A,bitdepth)
[41]101%whos A;
102B=double(A(:,:,1));
103windowsize=round(min(size(B,1),size(B,2))/20);
104windowsize=floor(windowsize/2)*2+1;
105ix=[1/2-windowsize/2:-1/2+windowsize/2];%
106%del=np/3;
107%fct=exp(-(ix/del).^2);
108fct2=cos(ix/(windowsize-1)/2*pi/2);
109%Mfiltre=(ones(5,5)/5^2);
110%Mfiltre=fct2';
111Mfiltre=fct2'*fct2;
112Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
113
[72]114C=filter2(Mfiltre,B);
[41]115C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
116C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
117C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
118C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
119C=tanh(B./(2*C));
120[n,c]=hist(reshape(C,1,[]),100);
121% figure;plot(c,n);
122
123[m,i]=max(n);
124c_max=c(i);
125[dummy,index]=sort(abs(c-c(i)));
126n=n(index);
127c=c(index);
128i_select = find(cumsum(n)<0.95*sum(n));
129if isempty(i_select)
130    i_select = 1:length(c);
131end
132c_select=c(i_select);
133n_select=n(i_select);
134cmin=min(c_select);
135cmax=max(c_select);
[73]136if isequal(bitdepth,16)
137    C=((C-cmin)/(cmax-cmin))*256*256;
138    C=uint16(C);
139else
140    C=((C-cmin)/(cmax-cmin))*256;
141    C=uint8(C);
142end
Note: See TracBrowser for help on using the repository browser.