ImageFile.convert(dtype, force_copy=False, uniform=False, normalise=True)

Convert an image to the requested data-type.

Warnings are issued in case of precision loss, or when negative values are clipped during conversion to unsigned integer types (sign loss).

Floating point values are expected to be normalized and will be clipped to the range [0.0, 1.0] or [-1.0, 1.0] when converting to unsigned or signed integers respectively.

Numbers are not shifted to the negative side when converting from unsigned to signed integer types. Negative values will be clipped when converting to unsigned integers.


Input image.


Target data-type.


Force a copy of the data, irrespective of its current dtype.


Uniformly quantize the floating point range to the integer range. By default (uniform=False) floating point values are scaled and rounded to the nearest integers, which minimizes back and forth conversion errors.


When converting from int types to float normalise the resulting array by the maximum allowed value of the int type.

  1. DirectX data conversion rules.

  2. Data Conversions. In “OpenGL ES 2.0 Specification v2.0.25”, pp 7-8. Khronos Group, 2010.

  3. Proper treatment of pixels as integers. A.W. Paeth. In “Graphics Gems I”, pp 249-256. Morgan Kaufmann, 1990.

  4. Dirty Pixels. J. Blinn. In “Jim Blinn’s corner: Dirty Pixels”, pp 47-57. Morgan Kaufmann, 1998.