Hi! So, I'm trying to use a particle image velocimetry (PIV) script and I am kind of stuck with a quiver function.
This is the main code for the PIV, where several functions are invoked (m. files for these functions can be found at http://folk.uio.no/jks/matpiv/Download/files.html ):
close all;clear all;clc;addpath(fullfile(cd,'piv & other functions'));global max_sp_dsply
USER INPUT pixel size in Microns, Time in sec
win_piv=64;pxl_sz=.178;tm_int=2;max_sp_dsply=.5;% ROI 1 Input the corordinates to define rectangle
r1_xmin = 176r1_xmax = 280r1_ymin = 30r1_ymax = 185% ROI 2
r2_xmin = 78r2_xmax = 133r2_ymin = 30r2_ymax = 181[filename, pathname] = uigetfile({'*.*'}, 'Input your stack (.tif)');avi_filename2=filename;img_info=imfinfo(fullfile(pathname,filename));Num_file=length(img_info)res_folder=fullfile(pathname,[filename '_Results']);mkdir(res_folder);mkdir(res_folder,'PIV velocity text');mkdir(res_folder,'PIV r1 velocity text');mkdir(res_folder,'PIV r2 velocity text');mkdir(res_folder,'PIV quiver image');for ifile=1:Num_file-1 f1=imread(fullfile(pathname,filename),ifile); f2=imread(fullfile(pathname,filename),ifile+1); [x,y,u1,v1]= matpiv(f1,f2,win_piv,tm_int,0.5,'single'); % matpiv(image1,image2,size of window,time_interval, overlap, looping for window)
u=pxl_sz*u1; % x, y, u1, v1 => matrix
v=pxl_sz*v1; % ~~~~~~~~~~~~~~~~~~~~~~ Filter and interpolate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v(isnan(v))=0; u(isnan(u))=0; % Make NaN values = 0
[lu,lv]=localfilt(x,y,u,v,2,'median'); [fu,fv]=naninterp(lu,lv,'weighted'); u=fu; v=fv; % fu, fv => matrix
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get x,y,u,v vector ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xx=x(:); yy=y(:); % xx, yy, uu, vv => vector
uu=u(:); vv=v(:); zz=sqrt((uu.^2)+(vv.^2)); temp_mat=[xx,yy,uu,vv]; csvwrite(fullfile(res_folder,'PIV velocity text',[avi_filename2 '_' num2str(ifile),'.txt']), temp_mat); % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get x,y,u,v of roi ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% ROI 1
idx_r1 = find(xx<=r1_xmax & xx>=r1_xmin & yy<=r1_ymax & yy>=r1_ymin); xx_r1 = xx(idx_r1); yy_r1 = yy(idx_r1); uu_r1 = uu(idx_r1); vv_r1 = vv(idx_r1); csvwrite(fullfile(res_folder,'PIV r1 velocity text',[avi_filename2 '_' num2str(ifile),'.txt']), [xx_r1,yy_r1,uu_r1,vv_r1]); abs_avg_uu_r1(ifile) = abs(mean(uu_r1)); abs_avg_vv_r1(ifile) = abs(mean(vv_r1)); % ROI 2 idx_r2 = find(xx<=r2_xmax & xx>=r2_xmin & yy<=r2_ymax & yy>=r2_ymin); xx_r2 = xx(idx_r2); yy_r2 = yy(idx_r2); uu_r2 = uu(idx_r2); vv_r2 = vv(idx_r2); csvwrite(fullfile(res_folder,'PIV r2 velocity text',[avi_filename2 '_' num2str(ifile),'.txt']), [xx_r2,yy_r2,uu_r2,vv_r2]); abs_avg_uu_r2(ifile) = abs(mean(uu_r2)); abs_avg_vv_r2(ifile) = abs(mean(vv_r2)); % ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Quiver plot ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xx(~vv)=0; yy(~uu)=0; % Removing null zeros during ploting
scaled_quiver2(xx,yy,uu,vv,f1); set(gcf, 'Position', get(0,'Screensize')); print('-dtiffnocompression','-r300',fullfile(res_folder,'PIV quiver image',[num2str(ifile),'.tif'])); close all;end% ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scale bar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmap = jet(36); % 1:35 level , define a color map with 35 levels
rgb_cmap = reshape(flipud(cmap),[length(cmap) 1 3]);figure;imagesc(rgb_cmap);x_y_w_h1=get(gcf,'Position');x_y_w_h2=get(gca,'Position');x_y_w_h1(3)=150;x_y_w_h2(3)=0.2;x_y_w_h2(1)=x_y_w_h2(1)+0.25;set(gcf,'Position',x_y_w_h1); set(gca,'Position',x_y_w_h2); set(gca,'XTickLabel','');set(gca,'TickLength', [0 0]);set(gca,'YTick',1:36);set(gca,'YTickLabel',{num2str(max_sp_dsply),'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','0'}); clrbar=getframe(gcf);imwrite(clrbar.cdata,fullfile(res_folder,'PIV quiver image','scale bar.tif'));xlswrite(fullfile(res_folder,'PIV quiver image','Absolute average u & v for r1 & r2.xlsx'),{'Frame','abs_avg_uu_r1','abs_avg_vv_r1','abs_avg_uu_r2','abs_avg_vv_r2'},1,'A1');xlswrite(fullfile(res_folder,'PIV quiver image','Absolute average u & v for r1 & r2.xlsx'),[[1:Num_file-1]' abs_avg_uu_r1' abs_avg_vv_r1' abs_avg_uu_r2' abs_avg_vv_r2'],1,'A2');close all;
So, my problem is at the Quiver plot step, where an error is displayed:
Undefined function or variable 'scaled_quiver2'.Error in main_PIV (line 129) scaled_quiver2(xx,yy,uu,vv,f1);
So probably the function on the respective m. file has a different name. I've downloaded all the m.files to the MATLAB folder, so I presume there's no function missing. It should be just a matter of different names, but I'm not sure. I think it refers to the vekplot2 function http://folk.uio.no/jks/matpiv/Download/Files/vekplot2.m, but not sure about this. So please, if anyone could give me some help here, I would really appreciate it!
Thanks a lot!
Joana
Best Answer