Professional Documents
Culture Documents
clear
% phases=[0 270 130];
% phases=[0 pi/2 pi 3*pi/2];
% phases=[-2*pi/3 0 2*pi/3];
% numims=length(phases);
% fs=1250;fc=40;usamp=256;
% testno=19;testno2=4
% % testdir=sprintf('test%i/',testno);
testdir=@(testno) sprintf('test%i/',testno);
% basedir=sprintf('3phasedemod/real/%s/',testdir(testno));
% % basedir=fullfile('3phasedemod/sim/',testdir(testno2));
% % mov='DSCN0743/';%test 20
% mov='DSCN0741/' ;%test 19;
% % mov='DSCN0710/' ;%test 14;
%
% % testdir=sprintf('test%i/',testno2);
%
%
% src='baseline/';
% fringedir='vert';
% %use this for sims
% % imdir=fullfile(basedir,src);
% % lutdir=basedir;
% % savedir=fullfile(imdir,'right/');
%
% %use this for real
% imdir=fullfile(basedir,mov,'imgs/3phase/',testdir(testno2),src);
% lutdir=fullfile(basedir,mov,'imgs/3phase/',testdir(testno2));
% savedir=fullfile(imdir,'left/');
%
% mkdir(savedir)
rows=[1:512];
cols=[1:512];
% phases=[0 2*pi/4 2*pi/2 2*3*pi/4];
% phases=[0 2*pi/3 4*pi/3];
phases=[-2*pi/3 0 2*pi/3];
numims=length(phases);
fringedir='vert';
% testno1=44; %use this ideal phase
testno1=19;
testno2=1;
otest=1;
src='baseline';
orient='right';
% (phases,testno1,src,orient,fringe_dir,varargin)
[basedir,imdir_o,imdir_b,lutdir,savedir_o,savedir_b]=load_dir_structure(testno1,
testno2,otest,orient,fringedir);
mkdir(savedir_o);mkdir(savedir_b);
if strcmp(src,'object'), imtgt=imdir_o;
else imtgt=imdir_b;
end
[imgs, imgsn]=read_imgs(imtgt,numims,'png',fspecial('gaussian',1,1),1);
figure(1),plot(imgs(300,:,1),'b'),title('line profile')
imwrite(imgs(:,:,1),strcat(savedir_b,'input.png'))
[bphasew, bphaseu,ba0,ba1,ba2] = get_phase_LS(imgs,phases);
[ubphasew, ubphaseu,uba0,uba1,uba2] = get_phase_LS(imgs,phases);
[bphasew bphaseu]=get_phase_3bucket(imgs);
bphasew4=bphasew;
bphaseu4=bphaseu;
j=imfilter(scaledata(imgs(:,:,1),-1,1),fspecial('average',5));
[bphasenw, bphasenu,ba0,ba1,ba2] = get_phase_LS(imgsn,phases);
mask=im2bw((ba1.^2+ba2.^2),0.02);
maskdil=imdilate(mask,strel('disk',5,4));
figure(3),displayImage(((imgs(:,:,1))),'gray'),title('input image'),shading 'int
erp'
% bphasew=bphasew.*mask;
figure(1),plot(bphasew(100,:),'b'),title('unwrapped phase')
figure(4),displayImage(bphasew,'gray'),title('wrapped phase'),shading 'interp'
% imgs=imgsn;
% object=bphasew;
% figure,surf(-(object-bphasew)),colormap('gray'),shading 'interp'
fringes=zeros(size(imgs));
background=zeros(size(imgs));
imgse=zeros(size(imgs));
imgses=zeros(size(imgs));
res=zeros(size(imgs));
ploton=1;
bamp=1;
i=1
for i=1:numims
close all
ploton=1;
%
if (i<5)
%
ploton=1;
%
end
%
%horz=[3 3 19 1,3,8]
%vert=[3 3 21 1,3,11]
[fringes(:,:,i), background(:,:,i)]=extractImageTQWT((imgs(:,:,i)),3,3,21,1,
3,11,fringedir,0);
%
[fringesr(:,:,i), backgroundr(:,:,i)]=extractImageTQWT(res(:,:,i),1,3,11,
1,3,8,'horz',0);
%
resr=res(:,:,i)-fringesr(:,:,i)-backgroundr(:,:,i);
%
figure,imagesc(EnvMean),colormap('gray'),title('Residue After Fringe Extra
ction')
res(:,:,i) = imgs(:,:,i)-fringes(:,:,i)-background(:,:,i);
res_dn=bpd_image(res(:,:,i),7.15,1000,150);
res(:,:,i)=res(:,:,i)-res_dn;
figure,imagesc(res_dn),colormap('gray'),title('denoised-residue')
figure,imagesc(res(:,:,i)),colormap('gray'),title('residue-resdn')
[modr, EnvMeanr]=OEMDV(res(:,:,i),1.0952);
res(:,:,i)=modr;
res_dn=bpd_image(res(:,:,i),2,100,1500);
%horz=1.52 res=mod
[modr, EnvMeanr]=OEMDV(res(:,:,i),3.0952);
res(:,:,i)=modr;
% src='baseline';
if strcmp(src,'baseline')
[lutmean,lutmed,lut_map, lut_tot,bideal_map,meant]=get_lut_b((bphaseew(:,:).
*maskdil(:,:)),512,fringedir,1);
save(fullfile(savedir_b,strcat('lut','.mat')),'lutmean','lutmed','lut_map','
lut_tot','meant')
end
lut=load(fullfile(savedir_b,strcat('lut','.mat')));
[bcorr_map,bideal_map]=correct_phase_image_c(((bphaseew.*maskdil)),lut.lutmean,5
12,fringedir);
% bideal_map=fliplr(bideal_map);
% bcorr_map=fliplr(bcorr_map);
savedir_b
% for i=1:size(meant,2)
% figure(100),plot(meant(:,i)),
% pause(0.1)
% end
% hold on,plot(meant(:,3),'r')
% plot(meant(:,4),'m'),plot(meant(:,5),'g'),plot(meant(:,6),'k')
% plot(meant(:,7),'r+'),plot(meant(:,8),'m+'),plot(meant(:,9),'g+'),plot(meant(:
,10),'k+')
bcorr_mapu= double(Miguel_2D_unwrapper(single((bcorr_map))));
bideal_mapu= double(Miguel_2D_unwrapper(single((bideal_map))));
bideal_mapu = imresize(bideal_mapu,size(bcorr_mapu));
sdw=atan2(imgses(:,:,1),imag(sd(:,:,1)));
sdu=double(Miguel_2D_unwrapper(single(sdw)));
maskdil=double(maskdil);
% maskdil(maskdil==0)=NaN;
% mask=im2bw((ba1e.^2+ba2e.^2),0.4e-3);
% load(strcat(sprintf('3phasedemod/real/'),'neigh.mat'));
% maskdil=imfill(imdilate(mask,strel('arbitrary',neigh)),'holes');
% maskdil(:,594:size(maskdil,2))=0;
v=(bcorr_mapu-bideal_mapu).*maskdil;%v(v==0)=NaN;v(v<5)=NaN;v(v>7)=NaN;
v2=(bphaseeu-bideal_mapu).*maskdil;
% (200:350,300:480)
figure(4),displayImage(bideal_mapu,'gray'),title('wrapped phase'),shading 'inter
p'
% row=[65:400];
% col=[300:700];
row=[28:438];
col=[125:550];
figure(7),surf(v(row,col)-mean2(v(row,col))),colormap('jet'),shading 'interp',co
lorbar
ttl=sprintf('Phase Error For Corrected Separated Fringe\n Using Proposed Method'
)
title(ttl,'FontSize',24)
xlabel('x-pixel'),ylabel('y-pixel'),zlabel('phase error')
zlim([-0.5 0.5]),caxis([-0.5 0.5])
figure(8),surf(v2(row,col)-mean2(v2(row,col))),colormap('jet'),shading 'interp',
colorbar
% title('Phase Error For Un-Corrected Separated Fringe','FontSize',24)
tmp=fliplr(bphasenw.*maskdil);
maskdil=fliplr(maskdil);
figure(10),hold off,imagesc(tmp),colormap('gray'),hold on,
for i=1:size(maskdil,1)
min(tmp(i,:))
[r,c] = find(tmp(i,:)<0,2,'first')
maskdil(i,1:c)=0;
plot(c,i,'r')
end
maskdil=fliplr(maskdil);
bphnwm=fliplr(tmp).*maskdil;
bphnum = double(Miguel_2D_unwrapper(single(bphnwm)));
figure(10),imagesc(bphnwm.*maskdil),colormap('gray')
figure(11),imagesc(bphnum.*maskdil),colormap('gray')
bphnum=bphasenu.*maskdil;
bphnwm=bphasenw.*maskdil;
bpheum=bphaseeu.*maskdil;
bphewm=bphaseew.*maskdil;
srcf=src(1:length(src)-1);
%use this for real
% imdir=fullfile(basedir,mov,'imgs/3phase/',testdir(testno2),srcf);
% savedir=fullfile(imdir,'right/');
%use this for sims
% imdir=fullfile(basedir,src);
% savedir=fullfile(imdir,'right/');
if strcmp(src,'baseline')
save(fullfile(savedir_b,strcat(src,'.mat')),'bphnum','bphnwm','bpheum','bphe
wm','mask','maskdil')
save(fullfile(savedir_b,strcat(src,'_corr.mat')),'bcorr_mapu','bcorr_map','b
ideal_map')
else
save(fullfile(savedir_o,strcat(src,'.mat')),'bphnum','bphnwm','bpheum','bphe
wm','mask','maskdil')
save(fullfile(savedir_o,strcat(src,'_corr.mat')),'bcorr_mapu','bcorr_map','b
ideal_map')
end
src='object';
%use this for sims
% imdir=fullfile(basedir,src);
% savedir=fullfile(imdir_o,'output/',tes);
%use this for real
% imdir=fullfile(basedir,mov,'imgs/3phase/',testdir(testno2),src);
% savedir=fullfile(imdir,'right/');
object=load(fullfile(savedir_o,strcat('object','_corr.mat')));
object_unco=load(fullfile(savedir_o,strcat('object','.mat')));
% mask=load(fullfile(savedir_o,strcat('object','.mat')));
src='baseline';
%use this for real
% imdir=fullfile(basedir,mov,'imgs/3phase/',testdir(testno2),src);
% savedir=fullfile(imdir,'right/');
%use this for sims
% imdir=fullfile(basedir,src);
% savedir=fullfile(imdir,'right/');
baseline=load(fullfile(savedir_b,strcat('baseline','_corr.mat')));
baseline_unco=load(fullfile(savedir_b,strcat('baseline','.mat')));
figure(4),displayImage(object_unco.bphewm.*maskdil,'gray'),title('Wrapped Phase'
,'FontSize',19),shading 'interp'
set(gca,'xtick',[],'ytick',[])
figure(5),displayImage(baseline.bcorr_mapu.*maskdil,'gray'),title('wrapped phase
'),shading 'interp'
close all
% cols=[400:670];
% rows=[37:480];
% cols=[550:1070];
% rows=[37:680];
rows=[28:438];
cols=[165:550];
blnc=imfilter(baseline.bcorr_mapu,fspecial('gaussian',30,5));
blnu=imfilter(baseline_unco.bpheum,fspecial('gaussian',30,5));
objc=imfilter(object.bcorr_mapu,fspecial('gaussian',3,80e-1));
obju=imfilter(object_unco.bpheum,fspecial('gaussian',3,80e-1));
res=-imfilter((objc-blnc)-mean2(objc-blnc),fspecial('gaussian',1,0.01));
res_uno=-imfilter((obju-blnu)-mean2(obju-blnu),fspecial('gaussian',1,0.01));
res_usep=-imfilter((ubphaseu.*maskdil-blnu)-mean2(obju-blnu),fspecial('gaussian'
,1,0.01));
res_uno(isnan(res_uno))=0;
% res=res-mean2(res);
res_uno=res_uno-mean2(res_uno);
% res_uno(res_uno<2.5)=NaN;
res_uno(res_uno>7)=NaN;
res(res>6.4)=NaN;
res(res<-1)=NaN;
res_uno=res_uno-mean2(res_uno(~isnan(res_uno)));
res=res-mean2(res(~isnan(res)));
masknan=double(maskdil);
% .*masknan(rows,cols)
% masknan(masknan==0)=NaN;
figure(1000),surf(res(rows,cols).*masknan(rows,cols)+2),colormap('gray'),shading
'interp'
title('Orthogonal Fringe Decomposed With Resonance Decomposition','FontSize',24)
zlim([-1 8])
%axis off
figure(1001),surf(res_uno(rows,cols).*masknan(rows,cols)),colormap('gray'),shadi
ng 'interp'
zlim([-1 7])
figure(1002),plot(res_uno(100,:).*masknan(100,:)),hold on,plot(res(100,:).*maskn
an(200,:),'r')
hleg=legend('normalised-uncorrected','normalised-corrected')
set(hleg,'FontSize',14)
% imdir=fullfile(basedir,mov,'imgs/3phase/',testdir);
% save(fullfile(imdir,'resleft.mat'),'res')