private void setCalibration() {
        if (matrix==null) return;           //fit failed
        ImageProcessor ip = imp.getProcessor();
        /* Calibrate the image to reflect zero level (8-bit and 16-bit only) */
        if (!(ip instanceof FloatProcessor) && !(ip instanceof ColorProcessor)) {
            Calibration cal = imp.getCalibration();
            double slope = 1;
            String valueUnit = "Gray Value";
            if (cal != null && cal.calibrated() && cal.getFunction()== Calibration.STRAIGHT_LINE) {
                slope = cal.getCoefficients()[1];
                valueUnit = cal.getValueUnit();
            }
            double[] coefficients = new double[] {-offset*slope, slope};
            cal.setFunction(Calibration.STRAIGHT_LINE, coefficients, valueUnit);
        }
        if (!shiftToDisplay && (ip instanceof ShortProcessor || ip instanceof FloatProcessor)) {
            double range = ip.getMax() - ip.getMin();
            ip.setMinAndMax(offset-range/2, offset+range/2);
        }
    }