Image.fixbad#

Image.fixbad(nan: int | float | Sequence[int | float] = 0.0, posinf: int | float | Sequence[int | float] | None = None, neginf: int | float | Sequence[int | float] | None = None) Image[source][source]#

Fix bad values in image

Parameters:
  • nan (scalar or array-like(n), optional) – value to replace NaN values, defaults to 0.0

  • posinf (scalar or array-like(n), optional) – value to replace positive infinity values, defaults to maximum value of image dtype

  • neginf (scalar or array-like(n), optional) – value to replace negative infinity values, defaults to negative maximum value of image dtype

Returns:

image with bad values fixed

Return type:

Image instance

Return an image where any pixel that contains a NaN or Inf values has been replaced by the specified replacement values.

The replacement value can be a scalar, in which case all bad values are replaced by the same value, or an array-like of length n, where n is the number of channels in the image, in which case each channel is replaced by the corresponding value.

By default NaN values are replaced by 0, positive infinity values are replaced by the maximum value of the image dtype, and negative infinity values are replaced by the negative maximum value of the image dtype.

Example:

>>> from machinevisiontoolbox import Image
>>> from numpy import nan, inf
>>> img = Image([[1, 2, 3], [4, nan, 6], [7, 8, inf]])
>>> img.fixbad(posinf=99).print()
    1.00  2.00  3.00
    4.00  0.00  6.00
    7.00  8.00 99.00