/**
   * Scales the range of <code>image</code> to an arbitrary min/max in a Region of Interest.
   *
   * @param image GrayImage to scale.
   * @param roi Region of Interest of <code>image</code>
   * @return <code>image</code>.
   */
  protected Image apply(GrayImage image, ROI roi) {
    int int_max = (int) float_max;
    int int_min = (int) float_min;

    float min = image.min(roi);
    float max = image.max(roi);
    float r = 0;
    float range = max - min;

    if (range == 0) range = 1; // to avoid divide by zero problems

    float value = 0;
    for (int y = roi.uy(); y <= roi.ly(); y++) {
      for (int x = roi.ux(); x <= roi.lx(); x++) {
        r = (float) image.get(x, y);
        value = (((r - min) / (range) * (int_max - int_min)) + int_min);
        image.set(x, y, (short) value);
      }
    }
    return image;
  }