def ContrastNBrightness1(img_array):
img_cv2 = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
img = copy.deepcopy(img_cv2)
st.write("Contrast and Brightness Settings")
orig = img.copy()
contrast = st.slider('Contrast', 0.0, 10.0, 1.0)
brightness = st.slider('brightness', 0.0, 500.0, 0.0)
img = np.clip(img * contrast + brightness, 0, 255)
img = imutils.resize(img, height=650)
st.image(img)
当我尝试使用st.image(img)显示图像时,它给了我错误。如图所示,数据超出[0,1]的范围。所以我尝试用255img = np.divide(img, 255)
除以img。它再次显示了相同的错误
如果我这样尝试:
def ContrastNBrightness1(img_array):
img_cv2 = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
img = copy.deepcopy(img_cv2)
st.write("Contrast and Brightness Settings")
orig = img.copy()
contrast = st.slider('Contrast', 0.0, 10.0, 1.0)
brightness = st.slider('brightness', 0.0, 500.0, 0.0)
img = np.clip(img * contrast + brightness, 0, 255)
img = imutils.resize(img, height=650)
cv2.imwrite('tempImage.jpg', img)
st.image('tempImage.jpg')
以上代码运行完美,能够显示图像。但在本例中,图像保存在本地存储器中,我想直接使用st.image(img)
显示图像。如何处理
目前没有回答
相关问题 更多 >
编程相关推荐