我有一个图像列表,我想调整它们的大小并将它们转换为黑白然后显示。以下是调整大小的代码:
resized_images = [skimage.transform.resize(image, (200, 600))
for image in images]
##code for changes to black and white
display_images_and_labels(resized_images, labels)
resized_images
是图片列表。我真的很感激一些帮助,一直坚持这一点。
答案 0 :(得分:1)
将彩色图像转换为灰度的最简单方法是将参数as_grey=True
传递给imread
函数。或者,您可以使用rgb2gray
。试试这段代码:
from skimage import io, transform
import matplotlib.pyplot as plt
fnames = ['https://i.stack.imgur.com/itbUo.jpg',
'https://i.stack.imgur.com/qIAhP.jpg']
fig, axes = plt.subplots(nrows=len(fnames), ncols=1)
fig.tight_layout()
for i, name in enumerate(fnames):
img = io.imread(name, as_grey=True)
resized = transform.resize(img, (200, 600))
axes[i].imshow(resized, cmap='gray')
axes[i].set_title(name)
答案 1 :(得分:1)
快速补充Tonechas答案:
image = io.imread(file, as_gray=True)
它不是as_grey
,它是as_gray