plenoptic.convert_float_to_int#

plenoptic.convert_float_to_int(image, dtype=<class 'numpy.uint8'>)[source]#

Convert numpy array from float to 8 or 16 bit integer.

We work with float images that lie between 0 and 1, but for saving them (either as png or in a numpy array), we typically want to convert them to 8 or 16 bit integers. This function does that by multiplying it by the max value for the target dtype (255 for 8 bit 65535 for 16 bit) and then converting it to the proper type.

Parameters:
  • image (ndarray) – The image to convert, with max less than or equal to 1.

  • dtype (Literal[<class 'numpy.uint8'>, <class 'numpy.uint16'>] (default: <class 'numpy.uint8'>)) – The target data type.

Return type:

ndarray

Returns:

image – The converted image, now with specified dtype.

Raises:

ValueError – If image max is greater than 1.