[英]Images is not converting to gray scale
I have read all the images in a folder through OpenCV.我已经通过 OpenCV 阅读了文件夹中的所有图像。 Then converting to gray scale, using
pyplot
I have shown all the images.然后转换为灰度,使用
pyplot
我已经显示了所有图像。 But instead of grayscale images look like yellowish.但不是灰度图像看起来像黄色。
import glob
import cv2
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
images = [cv2.imread(file) for file in glob.glob(r"C:\Users\USER\Handcrafted dataset/*.jpg")]
for img in images:
img = rgb2gray(img)
plt.figure(figsize=(10,10))
plt.imshow(img)
Sample output:样品 output:
What should I do to convert them to proper grayscale images?我应该怎么做才能将它们转换为正确的灰度图像?
This happens because Matplotlib uses a colormap when plotting a single channel.这是因为 Matplotlib 在绘制单个通道时使用颜色图。 In their docs there are a statement saying:
在他们的文档中有一个声明说:
The input may either be actual RGB(A) data, or 2D scalar data, which will be rendered as a pseudocolor image .
输入可以是实际的 RGB(A) 数据,也可以是 2D 标量数据,它们将被渲染为伪彩色图像。 Note: For actually displaying a grayscale image set up the color mapping using the parameters
cmap='gray'
,vmin=0
,vmax=255
.注意:要实际显示灰度图像,请使用参数
cmap='gray'
、vmin=0
、vmax=255
设置颜色映射。
So, change your last line to:因此,将最后一行更改为:
plt.imshow(img, cmap='gray')
This will plot the channel using the gray mapping.这将 plot 使用灰度映射的通道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.