-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeepPIV_3DR_SmHisoStl.m
113 lines (105 loc) · 4.31 KB
/
DeepPIV_3DR_SmHisoStl.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
clc; clear; close all; warning('off');tic
dataset='150811_DeepPIV_BathoStyg_3DR_xlarge';
display(dataset);
n=2; %n=1 is body; n=2 is inner filter; n=3 is outer filter
val=1;
vel=10; %mm/s %UNKNOWN
% percent=0.05; %percent allowable change in imwarp transform
inc=1;
%retrieving data set-specific parameters
[dir,start,finish,fps,fstop,shutter,calib,red,aspectratio,contrast]=videoinfo(dataset,vel);
viddir=[dir,'clips/'];
indir=[dir,'input/'];
outdir=[dir,'output/'];
nFrames=finish-start;
%% extract body features manually
display('Extracting body features manually')
% im_file=[indir,dataset,'_',num2str(vel),'vel_IMAGEbody.mat'];
% mask_file=[indir,dataset,'_',num2str(vel),'vel_MASKbody.mat'];
% outdata=[outdir,dataset,'_',num2str(val),'val_',num2str(vel),'vel_hiso_body.mat'];
% outstl=[outdir,dataset,'_',num2str(val),'val_',num2str(vel),'vel_body.stl'];
if n==1
im_file=[indir,dataset,'_IMAGEbody.mat'];
mask_file=[indir,dataset,'_MASKbody.mat'];
outdata=[outdir,dataset,'_',num2str(val),'val_hiso_body.mat'];
outstl=[outdir,dataset,'_',num2str(val),'val_body.stl'];
outmov=[outdir,dataset,'_',num2str(val),'val_body.mp4'];
outsm=[indir,dataset,'_',num2str(vel),'vel_IMAGEsm.mat'];
elseif n==2
im_file=[indir,dataset,'_IMAGEfilter.mat'];
mask_file=[indir,dataset,'_MASKfilter.mat'];
outdata=[outdir,dataset,'_',num2str(val),'val_hiso_filt.mat'];
outstl=[outdir,dataset,'_',num2str(val),'val_filt.stl'];
outmov=[outdir,dataset,'_',num2str(val),'val_filt.mp4'];
outsm=[indir,dataset,'_',num2str(vel),'vel_IMAGEfiltsm.mat'];
% im_file=[indir,dataset,'_IMAGEfilternew.mat'];
% mask_file=[indir,dataset,'_MASKfilternew.mat'];
% outdata=[outdir,dataset,'_',num2str(val),'val_hiso_filtnew.mat'];
% outstl=[outdir,dataset,'_',num2str(val),'val_filtnew.stl'];
% outmov=[outdir,dataset,'_',num2str(val),'val_filtnew.mp4'];
% outsm=[indir,dataset,'_',num2str(vel),'vel_IMAGEfiltsmnew.mat'];
% outdata=[outdir,dataset,'_',num2str(val),'val_hiso_filtmask.mat'];
% outstl=[outdir,dataset,'_',num2str(val),'val_filtmask.stl'];
% outmov=[outdir,dataset,'_',num2str(val),'val_filtmask.mp4'];
% outsm=[indir,dataset,'_',num2str(vel),'vel_IMAGEfiltmasksm.mat'];
elseif n==3
im_file=[indir,dataset,'_IMAGEfilterout.mat'];
mask_file=[indir,dataset,'_MASKfilterout.mat'];
outdata=[outdir,dataset,'_',num2str(val),'val_hiso_filtout.mat'];
outstl=[outdir,dataset,'_',num2str(val),'val_filtout.stl'];
outmov=[outdir,dataset,'_',num2str(val),'val_filtout.mp4'];
outsm=[indir,dataset,'_',num2str(vel),'vel_IMAGEoutsm.mat'];
end
if exist(im_file,'file')==2
display(' Loading IMAGE stacks...');
load(im_file);
% load(mask_file);
% MASKfilter=IMAGEfilter;
% for i=1:1:size(IMAGEfilter,3)
% MASKfilter(:,:,i)=(IMAGEfilter(:,:,i)>0)*255;
% end
else
display(' Body points are not extracted. Run DeepPIV_3DR_ManualBody.m.')
break
end
%% Smoothing adjacent images in stack
display('Smoothing images in body image stack')
if n==3
IMAGEsm=smooth3(IMAGEout); %smooth images
elseif n==2
IMAGEsm=smooth3(IMAGEfilter); %smooth images
% IMAGEsm=smooth3(IMAGEfilternew); %smooth images
% IMAGEsm=smooth3(MASKfilter);
elseif n==1
IMAGEsm=smooth3(IMAGEbody); %smooth images
end
save(outsm,'IMAGEsm','-v7.3'); %save post-processing parameters
close all; clear IMAGEbody
%% plotting 3D reconstruction
display('Plotting 3D reconstruction');
h=figure(3);
set(h,'Position',[100,100,1200,1200]);
display([' Calculating isosurface data with val = ',num2str(val),'...']);
[X,Y,Z]=meshgrid(1:size(IMAGEsm,2),1:size(IMAGEsm,1),1:size(IMAGEsm,3));
newaspect=aspectratio/aspectratio(1,1);
xx=single(X)/newaspect(1);yy=single(Y)/newaspect(2);zz=single(Z)/newaspect(3);
clear X Y Z
fv=isosurface(xx,yy,zz,IMAGEsm,val,'verbose');
clear xx yy zz
display([' Saving isosurface data with val = ',num2str(val),'...']);
stlwrite(outstl,fv);
hiso=patch(fv,'FaceColor',[0.5,0.5,0.65],'EdgeColor','none');
save(outdata,'hiso');
display([' Plotting isosurface data with val = ',num2str(val),'...']);
isonormals(IMAGEsm,hiso)
alpha(0.2) %sets level of transparency
view(3)
camlight
lighting gouraud
grid on
daspect([1 1 1]);
% axis equal
%%
display([' Saving 3DR movie with val = ',num2str(val)],'...');
makevideo(outmov);
toc