我对 Python 完全陌生。我拍了一张彩色照片。然后将其转换为灰度图像。到目前为止还不错。但是当我尝试将这个灰度转换为二值图像时,我得到的是黄色和紫色的图像,而不是白色和黑色。
import matplotlib.pyplot as plt
import numpy as np
painting=plt.imread("ff.jpg")
print(painting.shape)
print("The image consists of %i pixels" % (painting.shape[0] * painting.shape[1]))
plt.imshow(painting);
#This displayed by color image perfectly
from skimage import data,io,color
painting_gray = color.rgb2gray(painting)
print(painting_gray)
io.imshow(painting_gray)
print("This is the Gray scale version of the original image")
#This displayed my gray scale image perfectly
#Now comes the code for binary image:
num = np.array(painting_gray)
print(num)
bin= num >0.5
bin.astype(np.int)
plt.imshow(bin)
#The display showed an image with yellow and purple color instead of white and black
我得到的图像图是:
请帮我获取黑白二值图像。