.
%%% Acknowledgments:
% Options |'derivative5'| and |'derivative7'| call the resp. functions of% P.Kovesi's toolboox available at:
% http://www.csse.uwa.edu.au/~pk/Research/MatlabFns/.%
%% Credit% (ISR-2/LANL)
%%% See also
% Ressembles:% ,
% .% Requires:
% ,% .
%% Function implementation
function [Gx,Gy] = grdmask(I, varargin)
%% % parsing parameters
error(nargchk(1, 12, nargin, 'struct'));
error(nargoutchk(1, 2, nargout, 'struct'));
if ~isnumeric(I) error('grdmask:inputerror','a matrix is required in input');
end
p = createParser('GRDMASK'); p.addOptional('method', 'sobel', @(x)ischar(x) && ...
any(strcmpi(x,{'matlab','diff','difference', 'backward','back', 'forward','for',... 'prewitt','prew', 'kirsch','kir', 'robinson','rob', 'circular','circ',...
'optimal','opt', 'ori','orientation', 'isotropic','iso', 'sobel','sob', ... 'roberts', 'derivative5','tap5', 'derivative7','tap7'})));
p.addOptional('map',[],@(x)isnumeric(x) || islogical(x));p.addOptional('axis','ij',@(x)ischar(x) && any(strcmpi(x,{'ij','xy'})));
% parse and validate all input arguments
p.parse(varargin{:}); p = getvarParser(p);
%%
% check parameters
if any(strcmpi(p.method,{'derivative5','tap5', 'derivative7','tap7'})) error('grdmask:methoderror', ...
'Kovesi''s library required with tap coefficients');
elseif ~isempty(p.map) && ~isequal(size(p.map),size(I(:,:,1))) error('grdmask:inputerror', ...
'input map must be same size as the input image domain');end
%%
% main computation
[X,Y,C] = size(I);
if isempty(p.map) || all(p.map(:)) [Gx,Gy] = grdmask_base(I, p.method, p.axis);
else [Gx,Gy] = grdmaskmap_base(I, p.map, p.method, p.axis);
end
%%% display
if p.disp
figure, subplot(1,2,1), imagesc(rescale(Gx,0,1)), axis image off,
title(['gx - axis ''' p.axis '''']); if C==1, colormap gray; end subplot(1,2,2), imagesc(rescale(Gy,0,1)), axis image off,
title(['gy - axis ''' p.axis '''']); if C==1, colormap gray; end figure,
imagesc(rescale(I,0,1)), axis image off; hold on; if C==1, colormap gray; end
[X,Y] = meshgrid(3:10:X-2,3:10:Y-2); if strcmpi(p.axis,'ij')
quiver(X, Y, max(Gy(X(1,:),Y(:,1),:),[],3), max(Gx(X(1,:),Y(:,1),:),[],3)); else
quiver(X, Y, Gx(X(1,:),Y(:,1)), -Gy(X(1,:),Y(:,1))); end
hold off; title('gradient field')end
end % end of grdmask
##### SOURCE END #####
-->