Return scaling and intercept min, max of data, given output type
Returns scalefactor and intercept to best fit data with given mn and mx min and max values into range of data type with type_min and type_max min and max values for type.
The calculated scaling is therefore:
scaled_data = (data-intercept) / scalefactor
Parameters : | mn : scalar
mx : scalar
out_type : numpy type
allow_intercept : bool
|
---|---|
Returns : | scalefactor : numpy scalar, dtype=np.maximum_sctype(np.float)
intercept : numpy scalar, dtype=np.maximum_sctype(np.float)
>>> scale_min_max(0, 255, np.uint8, False) : (1.0, 0.0) : >>> scale_min_max(-128, 127, np.int8, False) : (1.0, 0.0) : >>> scale_min_max(0, 127, np.int8, False) : (1.0, 0.0) : >>> scaling, intercept = scale_min_max(0, 127, np.int8, True) : >>> np.allclose((0 - intercept) / scaling, -128) : True : >>> np.allclose((127 - intercept) / scaling, 127) : True : >>> scaling, intercept = scale_min_max(-10, -1, np.int8, True) : >>> np.allclose((-10 - intercept) / scaling, -128) : True : >>> np.allclose((-1 - intercept) / scaling, 127) : True : >>> scaling, intercept = scale_min_max(1, 10, np.int8, True) : >>> np.allclose((1 - intercept) / scaling, -128) : True : >>> np.allclose((10 - intercept) / scaling, 127) : True : |
Notes
The large integers lead to python long types as max / min for type. To contain the rounding error, we need to use the maximum numpy float types when casting to float.