RuntimeError: Data is outside [0.0, 1.0] and clamp is not set

I am trying to display an image using st.image, after performing certain computations but face this error when I am trying to display the image

Hi @Namya_LG, are you using opencv to process your image before calling st.image?

If so, could you try setting clamp=True and channels='BGR when calling st.image?
Suppose opencv returns the image opencv_img:

st.image(opencv_img, clamp=True, channels='BGR')

Let us know if that helps!

Happy Streamlit-ing! :balloon:
Snehan

1 Like

I am trying to display a grayscale image using and have set the clamp=True, but when I set channels to β€˜BGR’, it doesn’t work.

I removed the parameter channels considering that I am using a grayscale image, but that gives me an image whose pixels are all 255

The way I was able to solve it, was to load it into cv2.imwrite and then render the image, given as :

    blurred_img = apply_convolution(img, kernel_blur, height, width)
    cv2.imwrite('temporary.jpg', blurred_img)
    st.image('temporary.jpg')
1 Like