adjgriddir

PURPOSE ^

ADJGRIDDIR adjusts the direction of the extracted grid to ensure consistency across all images.

SYNOPSIS ^

function gridout=adjgriddir(grid)

DESCRIPTION ^

 ADJGRIDDIR adjusts the direction of the extracted grid to ensure consistency across all images.
 
 ADJGRIDDIR examines the direction of the grid rows and columns. It then
 consequently adjusts the grid to a consistent direction.
 
 USAGE:
     gridout=adjgriddir(grid);
 
 INPUTS:
     grid: MxNx2 array, output of FILTERGRID

 OUTPUTS:
     gridout: adjusted MxNx2 or NxMx2 array

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function gridout=adjgriddir(grid)
0002 % ADJGRIDDIR adjusts the direction of the extracted grid to ensure consistency across all images.
0003 %
0004 % ADJGRIDDIR examines the direction of the grid rows and columns. It then
0005 % consequently adjusts the grid to a consistent direction.
0006 %
0007 % USAGE:
0008 %     gridout=adjgriddir(grid);
0009 %
0010 % INPUTS:
0011 %     grid: MxNx2 array, output of FILTERGRID
0012 %
0013 % OUTPUTS:
0014 %     gridout: adjusted MxNx2 or NxMx2 array
0015 
0016 % turn off unwanted warnings
0017 warning('off','MATLAB:polyfit:PolyNotUnique');
0018 warning('off','MATLAB:polyfit:RepeatedPointsOrRescale');
0019 
0020 rowslope=zeros(1,size(grid,1));
0021 colslope=zeros(1,size(grid,2));
0022 
0023 % get slopes of rows
0024 for rowindx=1:size(grid,1)
0025     currentrowx=grid(rowindx,:,1);
0026     currentrowy=grid(rowindx,:,2);
0027     currentrowx=currentrowx(currentrowx>0);
0028     currentrowy=currentrowy(currentrowy>0);
0029     P=polyfit(currentrowx,currentrowy,1);
0030     rowslope(rowindx)=abs(P(1));
0031 end
0032 
0033 % get slopes of columns
0034 for colindx=1:size(grid,2)
0035     currentcolx=grid(:,colindx,1);
0036     currentcoly=grid(:,colindx,2);
0037     currentcolx=currentcolx(currentcolx>0);
0038     currentcoly=currentcoly(currentcoly>0);
0039     P=polyfit(currentcolx,currentcoly,1);
0040     colslope(colindx)=abs(P(1));
0041 end
0042 
0043 % reset warnings
0044 warning('on','MATLAB:polyfit:PolyNotUnique');
0045 warning('on','MATLAB:polyfit:RepeatedPointsOrRescale');
0046 
0047 rowslope=mean(rowslope);
0048 colslope=mean(colslope);
0049 
0050 % adjust for the higher slope
0051 if colslope>rowslope
0052     gridtemp(:,:,1)=rot90(grid(:,:,1));
0053     gridtemp(:,:,2)=rot90(grid(:,:,2));
0054     gridout=gridtemp;
0055 else
0056     gridout=grid;
0057 end

Generated on Sun 04-Apr-2010 17:13:59 by m2html © 2005