function points = linear_warp(points, lo, hi, ref_lo, ref_hi)
% LINEAR_WARP: Apply a linear warp to the points.
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      linear_warp(points, lo, hi, ref_lo, ref_hi)
%
%    INPUT/S
%
%      -points:
%           The points before warping
%
%      -lo:
%           ?
%
%      -hi:
%           ?
%
%      -ref_lo:
%           ?
%
%      -ref_hi:
%           ?
%           
%    OUTPUT/S
%
%      -points:
%           The points after warping
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      POOR_LINEAR_WARP
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 25th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

image_width = max(points); 
          % get the maximum of points. Why is that width??
if ((hi - lo)<=0) 
  disp('Invalid values of high and low. Low must be lower than high');
  return; % break out of function
end
% Smith: line up the edge points, do linear stretch in between!

% RSS: The following 3 sections are quite mysterious. They implement
%      a warp in some way. 

% Smith: first section - between 1 and lo
%scale_factor1 = (ref_lo-1)/(lo-1);
scale_factor1 = (lo-1)/(ref_lo-1);
points(1:ref_lo,:) = (points(1:ref_lo,:)-1)*scale_factor1 + 1;

% Smith: second section
scale_factor2 = (hi - lo)/(ref_hi-ref_lo);
points(ref_lo+1:ref_hi-1,:) = (points(ref_lo+1:ref_hi-1,:) - ref_lo)*scale_factor2 + lo;
%scale_factor2 = (ref_hi - ref_lo)/(hi-lo);
%points(:,lo+1:hi-1) = (points(:,lo+1:hi-1) - lo)*scale_factor2 + ref_lo;

% Smith: third section
scale_factor3 = (image_width-hi)/(image_width-ref_hi);
points(ref_hi:image_width,:) = ...
  (points(ref_hi:image_width,:) - ref_hi)*scale_factor3 + hi;
%scale_factor3 = (image_width-ref_hi)/(image_width-hi);
%points(:,hi:image_width) = ...
%  (points(:,hi:image_width) - hi)*scale_factor3 + ref_hi;