function [isIn,epipole] = isEpipoleInImage(f,imageSize)
%isEpipoleInImage Determine whether the epipole is inside the image.
%   Assuming F is a 3-by-3 fundamental matrix computed from stereo images
%   I1 and I2, i.e., if P1, a point in I1, corresponds to P2, a point in
%   I2, then [P2,1] * F * [P1,1]' = 0.
%
%   ISIN = isEpipoleInImage(F,IMAGESIZE) determines whether the epipole
%   is inside I1. IMAGESIZE is the size of I1 and is in the format returned
%   by the function SIZE.
% 
%   ISIN = isEpipoleInImage(F',IMAGESIZE) determines whether the epipole
%   is inside I2. IMAGESIZE is the size of I2 and is in the format returned
%   by the function SIZE.
% 
%   [ISIN,EPIPOLE] = isEpipoleInImage(...) also returns the epipole.
%
%   Class Support
%   -------------
%   F must be double or single. IMAGESIZE must be double, single, or
%   integer. 
%
%   Example 1
%   ---------
%   load stereoPointPairs
%   f = estimateFundamentalMatrix(matched_points1, matched_points2, ...
%     'NumTrials', 2000);
%   imageSize = [200 300];
%   [isIn,epipole] = isEpipoleInImage(f,imageSize)
%   
%   Example 2
%   ---------
%   f = [0 0 1; 0 0 0; -1 0 0];
%   imageSize = [200, 300];
%   [isIn,epipole] = isEpipoleInImage(f',imageSize)
%
% See also estimateFundamentalMatrix, estimateUncalibratedRectification.

% Copyright 2010 The MathWorks, Inc.
% $Revision: 1.1.6.3 $  $Date: 2011/02/21 07:17:32 $

checkInputs(f, imageSize);
isXY = cvstGetCoordsChoice('fcnIsEpipoleInImage');
[isIn,epipole] = cvalgIsEpipoleInImage(f, imageSize, isXY);

%========================================================================== 
function checkInputs(f, imageSize)
%--------------------------------------------------------------------------
% Check F
%--------------------------------------------------------------------------
validateattributes(f, {'double', 'single'}, ...
  {'2d', 'nonsparse', 'real', 'size', [3,3]},...
  mfilename, 'F');

%--------------------------------------------------------------------------
% Check IMAGESIZE
%--------------------------------------------------------------------------
validateattributes(imageSize, {'single', 'double', 'int8', 'int16', ...
  'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'}, ...
  {'vector', 'nonsparse', 'nonempty', 'real', 'positive', 'integer'},...
  mfilename, 'IMAGESIZE');

if length(imageSize) < 2
  error('vision:isEpipoleInImage:invalidImageSize', ...
    'Expected IMAGESIZE to be a vector of two or more elements.');
end
