Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers)

Ankita Shinde picture Ankita Shinde · Apr 4, 2018 · Viewed 59.4k times · Source

I tried to run the graph cut algorithm for a slice of an MRI after converting it into PNG format. I keep encountering the following problem:

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

This is even after setting vmin and vmax as follows:

plt.imshow(out, vmin=0, vmax=255)

Answer

Dat picture Dat · Jul 10, 2018

Cast the image to np.uint8 after scaling [0, 255] range will dismiss this warning. It seems like a feature in matplotlib, as discussed in this issue.

plt.imshow((out * 255).astype(np.uint8))