code: public static boolean isInside( int width , int height, 
  									double tl_x , double tl_y , 
  									double regionSize  , double sampleSize )
  	{
  		int w = (int)(sampleSize+0.5);
  		int r = w/2 + w%2; // be conservative  and round up
  
  		// the extra minus one is because integral images are being used
  		int x0 = (int)(tl_x+0.5) - r - 1;
  		int y0 = (int)(tl_y+0.5) - r - 1;
  
  		if( x0 < 0 || y0 < 0)
  			return false;
  
  		int x1 = (int)(tl_x+regionSize+0.5) + r;
  		int y1 = (int)(tl_y+regionSize+0.5) + r;
  
  		if( x1 >= width || y1 >= height )
  			return false;
  
  		return true;
  	}
docs: <p>
  Tests to see if the rectangular region being sampled is contained inside the image.  Sampling
  is done using a square region with the specified size, where size corresponds to the length
  of each side.  The sample region's size is discretized and rounded up, making this a conservative
  estimate for containment.
  </p>
  <p>
  This takes in account how integral images are read.  To read in a rectangular region the pixel
  below the lower left corner is read, which results in an extra minus along enough axis for the
  lower bound.  It is also assumed that points are discretized by rounding.
  </p>
  
  
  @param width Image's width.
  @param height Image's height.
  @param tl_x Top left corner of region being sampled.
  @param tl_y Top left corner of region being sampled.
  @param regionSize Size of the region being sampled.
  @param sampleSize Length of each side in the sample region.  See comment above.
  @return If all samples are contained inside the image.