function rect=getLineRegion(x,y,dimImage)
% Gets the rectangular region bounded by the line selected on the plot
% Input: x and y coordinates of the line, dimensions of the image
% Output: rectangle array corresponding to the region
% Kevin Baggett Wed Aug  8 17:06:57 UTC 2001

 if x(1) > x(2) % exchange if line selected from right to left
     tempx=x(2);
 else
     tempx=x(1);
 end
 
 if y(1) < y(2) %exchange if line selected from top to bottom
     tempy=y(1);
 else
     tempy=y(2);
 end
 sidex=abs(diff(x));
 sidey=abs(diff(y));
 
 if sidey > 100 & sidex > 100
     rect=[tempy; tempx; sidey; sidex];
 elseif sidey < 100 %horizontal line
     if mean(y)-150 < 0 | mean(y)+150 > dimImage(1)
         rect=[];
         return;
     else
         adjustedy=mean(y)-150;
     end
     %set default rectangle width to 300
     rect=[adjustedy; tempx; 300; sidex];
 elseif sidex < 100 %vertical line
     if mean(x)-100 < 0 | mean(x)+100 > dimImage(2)
         rect=[];
         return;
     else
         adjustedx=mean(x)-100;
     end
     %set default rectangle length to 200
     rect=[tempy; adjustedx; sidey; 200];
 end
