private static double makeScale(Mat img,Size approxSize,boolean maximize,boolean integerScale){
  Size imageSize=img.size();
  double ratioWidth=approxSize.width / imageSize.width;
  double ratioHeight=approxSize.height / imageSize.height;
  double ratio=maximize ? Math.max(ratioWidth,ratioHeight) : Math.min(ratioWidth,ratioHeight);
  if (MathUtil.equal(ratio,1))   return 1;
  if (integerScale) {
    double scale=(ratio < 1) ? 1 / ratio : ratio;
    scale=maximize ^ (ratio < 1) ? Math.ceil(scale) : Math.floor(scale);
    return (ratio < 1) ? 1 / scale : scale;
  }
 else {
    return ratio;
  }
}

private static double makeScale ( Mat img , Size approxSize , boolean maximize , boolean integerScale ) { Size imageSize = img . size ( ) ; double ratioWidth = approxSize . width / imageSize . width ; double ratioHeight = approxSize . height / imageSize . height ; double ratio = maximize ? Math . max ( ratioWidth , ratioHeight ) : Math . min ( ratioWidth , ratioHeight ) ; if ( MathUtil . equal ( ratio , 1 ) ) return 1 ; if ( integerScale ) { double scale = ( ratio < 1 ) ? 1 / ratio : ratio ; scale = maximize ^ ( ratio < 1 ) ? Math . ceil ( scale ) : Math . floor ( scale ) ; return ( ratio < 1 ) ? 1 / scale : scale ; } else { return ratio ; } }
scales an image to an approximate size . the scale will always be equal on the x and y axis , regardless of the approxsize .
