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

假如想象 提交于 2019-12-04 17:06:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!