from High Speed PIV and Hotwire post processing by Anurag
High Speed PIV and hotwire post processing routines

regproc(frame1,frame2, uth_ll,uth_ul,uth_st)
function regproc(frame1,frame2, uth_ll,uth_ul,uth_st)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                                                  %%
%%   Copyright (C) 2005-2007  Anurag Singh                                                          %%
%%                                                                                                  %%
%%       This program/code snippet/file (hence forth refered as "library")                          %%
%%       is free software; you can redistribute it and/or                                           %%
%%       modify it under the terms of the GNU Lesser General Public                                 %%
%%       License as published by the Free Software Foundation; either                               %%
%%       version 2.1 of the License, or (at your option) any later version.                         %%
%%                                                                                                  %%
%%       This library is distributed in the hope that it will be useful,                            %%
%%       but WITHOUT ANY WARRANTY; without even the implied warranty of                             %%
%%       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                          %%
%%       Lesser General Public License for more details.                                            %%
%%                                                                                                  %%
%%       You should have received a copy of the GNU Lesser General Public                           %%
%%       License along with this library; if not, write to the Free Software                        %%
%%       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                  %%
%%                                                                                                  %%
%%   FILENAME:                                                                                      %%
%%      regproc.m                                                                                   %%
%%                                                                                                  %%
%%   AUTHOR:                                                                                        %%
%%                                                                                                  %%
%%      Anurag Singh,                                                                               %%
%%      MS, 2007                                                                                    %%
%%      Aerospace Engineering & Mechanics                                                           %%
%%      University of Minnesota - Twin Cities.                                                      %%
%%      Minneapolis, MN 55455 (USA)                                                                 %%
%%                                                                                                  %%
%%      (currently working at: Exa Corporation, Burlington, MA 01803)                               %%
%%                                                                                                  %%
%%   CONTACT/EMAIL:                                                                                 %%
%%                                                                                                  %%
%%      anurag@aem.umn.edu                                                                          %%
%%      anurag9@gmail.com                                                                           %%
%%                                                                                                  %%
%%   SOURCE CONTROL INFORMATION:                                                                    %%
%%      None (since I was planning on putting it under source control since it has                  %%
%%      reached the critical file system size. Would be a good thing to put it under                %%
%%      source control while making changes.                                                        %%
%%                                                                                                  %%
%%   DESCRIPTION:                                                                                   %%
%%                                                                                                  %%
%%                                                                                                  %%
%%                                                                                                  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


global numregions regions slowregion u_norm region_lenpdf showplot thresh pix_m u_tau nu


% compute conversion factors for normalizing
lenconvfac = pix_m*u_tau/nu;

null_pdf_vars;

% Initialize various limits
%uth_ll = 1.75;
%uth_ul = 1.75;
%uth_st = 0.25;

reg_xl  = 5;             % joining filter streamwise size
reg_yl  = 2;
arealim = 20;


regions = [];
regions = struct('length',{},'width',{},'area',{},'minu',{},'minux',{},'minuy',{},'frame',{});
thresh = [];
thresh = struct('value',{},'regions',regions);


disp(['Identifying slow speed regions ... ']);
m = 1;

for uthresh=uth_ll:uth_st:uth_ul
   
   disp(['Running for uthresh = ', num2str(uthresh), ' ...']);
   
   regions  = [];
   regions  = struct('length',{},'width',{},'area',{},'minu',{},'minux',{},'minuy',{},'frame',{});
   regcount = 1;           % Reset the region count to 1 and then add the regions to region array for each frame

   for frame=frame1:frame2

      findslowregs(frame, reg_xl, reg_yl, arealim, uthresh, 0);         % identify the regions (the regions are not being connected in this case)
      
      for idtag=1:numregions

         [xc yc] = find(slowregion == idtag);

         regions(regcount).length  = (max(xc) - min(xc) + 1) * lenconvfac;
         regions(regcount).width   = (getregwidth(idtag)) * lenconvfac; 
         regions(regcount).area    = (size(xc,1)) * lenconvfac^2;
         regions(regcount).minu    = min(min(squeeze(u_norm(frame,:,:)).*(slowregion==idtag)));
         [regions(regcount).minux regions(regcount).minuy]  = find(squeeze(u_norm(frame,:,:))==regions(regcount).minu);
         regcount = regcount + 1;
         regions(regcount).frame   = frame;
      end

      %region_length_pdf;
      %calc_area_pdf;
      %calc_minu_pdf;
   end   

   thresh(m).value   = uthresh;
   thresh(m).regions = regions;
   m = m + 1;
end
region_lenpdf = [regions(:).length];

disp(['done !!!']);

return;





% Find average region width
function width=getregwidth(idtag)

global slowregion

width = 0;
[xc yc] = find(slowregion == idtag);

for m=min(xc):max(xc)         % scan the region with idtag from left to right

   [x y] = find(slowregion(m,:) == idtag);         % note that in this case x will always be 1 since slowregion is 1,NY arrar, y is only of ineterest to us
   
   width = width + max(yc) - min(yc) + 1;
end

width = width / (max(xc) - min(xc) + 1) ;

return;








function null_pdf_vars()
global region_apdf region_minupdf region_lenpdf region_widpdf
region_apdf    = [];
region_minupdf = [];
region_lenpdf  = [];
region_widpdf  = [];

return;





function region_length_pdf()
global region_lenpdf regions
region_lenpdf = [region_lenpdf [regions(:).length]];
return;



Contact us at files@mathworks.com