问题
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)
回答1:
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))
回答2:
If you want to show it, you can use img/255
. I haven't figured out what's going on.
Or
np.array(img,np.int32)
回答3:
Instead of plt.imshow(out)
, use plt.imshow(out.astype('uint8'))
. That's it!
来源:https://stackoverflow.com/questions/49643907/clipping-input-data-to-the-valid-range-for-imshow-with-rgb-data-0-1-for-floa