gradient_perso

PURPOSE ^

GRADIENT_PERSO - gradient computation

SYNOPSIS ^

function [ax,ay ]=gradient_perso(a,dx,dy,n);

DESCRIPTION ^

GRADIENT_PERSO - gradient computation

   INPUT a,dx,dy,n where a is the scalar value, dx and dy the spacing of one pixel
   in a and n is the width wanted in the gradient computation, in pixels.

   Usage:
      [ax,ay ]=gradient_perso(a,dx,dy,n)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ax,ay ]=gradient_perso(a,dx,dy,n);
0002 %GRADIENT_PERSO - gradient computation
0003 %
0004 %   INPUT a,dx,dy,n where a is the scalar value, dx and dy the spacing of one pixel
0005 %   in a and n is the width wanted in the gradient computation, in pixels.
0006 %
0007 %   Usage:
0008 %      [ax,ay ]=gradient_perso(a,dx,dy,n)
0009 
0010 s=size(a);
0011 ax=zeros(s(1),s(2));
0012 ay=zeros(s(1),s(2));
0013 
0014 for k=n+1:s(1)-n,
0015    if mod(k,10)==0,
0016       disp(k/s(1)*100);
0017    end
0018    
0019    for j=n+1:s(2)-n,
0020       if isnan(a(k,j)),
0021          ax(k,j)=NaN;
0022          ay(k,j)=NaN;
0023       else
0024          temp=a(k,j);
0025          temp2=a(k,j);
0026          
0027          count=1;
0028          while ~isnan(a(k,j+count)),
0029             temp=[temp a(k,j+count)];
0030             count=count+1;
0031             if count>n,
0032                count=count-1;
0033                break;
0034             end
0035             
0036          end
0037          count=1;
0038          while ~isnan(a(k,j-count)),
0039             temp=[a(k,j-count) temp];
0040             count=count+1;
0041             if count>n,
0042                count=count-1;
0043                break;
0044             end
0045             
0046          end
0047          
0048          count=1;
0049          while ~isnan(a(k+count,j)),
0050             temp2=[temp2 a(k+count,j)];
0051             count=count+1;
0052                if count>n,
0053                count=count-1;
0054                break;
0055             end
0056          
0057          end
0058          count=1;
0059          while ~isnan(a(k-count,j)),
0060             temp2=[a(k-count,j) temp2];
0061             count=count+1;
0062                if count>n,
0063                count=count-1;
0064                break;
0065             end
0066          
0067          end
0068            
0069          if length(temp)==1,
0070             ax(k,j)=NaN;
0071          else
0072             ax(k,j)=(temp(length(temp))-temp(1))/(length(temp)-1)/dx;
0073          end
0074          
0075          if length(temp2)==1,
0076             ay(k,j)=NaN;
0077          else
0078             ay(k,j)=(temp2(length(temp2))-temp2(1))/(length(temp2)-1)/dy;
0079          end
0080          
0081       end
0082    end
0083 end
0084 
0085          
0086           
0087           
0088           
0089           
0090           
0091

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003