% Bc. Michal Kubiš
% Fakulta elektrotechniky a komunikačních technologií na VUT v Brně
% Vedoucí: Ing. Petr Fedra
% 
% 21. 5. 2010
% založeno na algoritmu Petera Kovesiho

function plotridgeorient(orient, spacing, im, figno)

    if fix(spacing) ~= spacing
	error('spacing must be an integer');
    end
    
    [rows, cols] = size(orient);
    
    lw = 2;             % linewidth
    len = 0.8*spacing;  % length of orientation lines

    % Subsample the orientation data according to the specified spacing

    s_orient = orient(spacing:spacing:rows-spacing, ...
		      spacing:spacing:cols-spacing);

    xoff = len/2*cos(s_orient);
    yoff = len/2*sin(s_orient);    
    
    if nargin >= 3     % Display fingerprint image
	if nargin == 4
	    imshow(im, figno); hold on
	else
	    show(im); hold on
	end
    end
    
    % Determine placement of orientation vectors
    [x,y] = meshgrid(spacing:spacing:cols-spacing, ...
		     spacing:spacing:rows-spacing);
    
    x = x-xoff;
    y = y-yoff;
    
    % Orientation vectors
    u = xoff*2;
    v = yoff*2;
    
    quiver(x,y,u,v,0,'.','linewidth',2);
    
    axis equal, axis ij,  hold off
    