function [ lightingVectors, specMids ] = FindLightingVectors( sphereFileName, numberOfFiles )
%FINDLIGHTINGVECTOR Summary of this function goes here
%   Detailed explanation goes here

mask = imread(strcat(sphereFileName,'.mask.bmp'));
[rows, cols] = find(mask(:,:,1));

topWhite = min(rows);
bottomWhite = max(rows);
leftWhite = min(cols);
rightWhite = max(cols);

pixelRadius = ((rightWhite-leftWhite)+(bottomWhite-topWhite))/4;
xMid = leftWhite + pixelRadius;
yMid = topWhite + pixelRadius;

% viewing vector is always directly along the Z axis
R = [0,0,1];
lightingVectors = zeros(numberOfFiles,3);
specMids = zeros(numberOfFiles,3);

for(i=1:numberOfFiles)
    image = imread(strcat(sphereFileName,'.',int2str(i),'.bmp'));
    slice = image(:,:,1);
    slice = slice>=200;
    
    [rows,cols] = find(slice);
    topWhite = min(rows);
    bottomWhite = max(rows);
    leftWhite = min(cols);
    rightWhite = max(cols);
    
    xSpecMid = ((rightWhite-leftWhite)/2)+leftWhite;
    ySpecMid = ((bottomWhite-topWhite)/2)+topWhite;
    
    % find the normal vector
    xComp = xSpecMid - xMid;
    yComp = ySpecMid - yMid;
    zDistSq = xComp^2 + yComp^2;
    zComp = sqrt(pixelRadius^2 - zDistSq);
    
    normal = [xComp, yComp, zComp];
    normal = normal / norm(normal); %normalize it to be unit length
   
    lightingVectors(i,:) = 2 * dot(normal, R) * normal - R;
    specMids(i,1) = xSpecMid;
    specMids(i,2) = ySpecMid;
end


end

