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)
The most direct way is to just render your array to RGB using the colormap, and then change the pixels you want.
imshow. The matplotlib function imshow() creates an image from a 2-dimensional numpy array. The image will have one square for each element of the array. The color of each square is determined by the value of the corresponding array element and the color map used by imshow() .
As you have already found out, the return type of plt. imshow() is a matplotlib. image. AxesImage .
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With