[英]skimage.io.imread Versus cv2.imread
I am using and familiar with cv2
, today I was giving a try with skimage
.我正在使用并熟悉cv2
,今天我尝试使用skimage
。
I was trying to read an image using skimage
and cv2
.我试图使用skimage
和cv2
读取图像。 It seems that they both read the image perfectly.似乎他们都完美地阅读了图像。 But when I plot histograms of the image but read through different libraries ( skimage
and cv2
), the histogram shows a significant difference.但是当我绘制图像的直方图但读取不同的库( skimage
和cv2
)时,直方图显示出显着差异。
Would anyone help me by explaining the difference between the histograms?有人会通过解释直方图之间的差异来帮助我吗?
My code:我的代码:
import cv2
import skimage.io as sk
import numpy as np
import matplotlib.pyplot as plt
path = '../../img/lenna.png'
img1 = sk.imread(path, True)
img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
print(img1.shape)
print(img2.shape)
plt.subplot(2, 2, 1)
plt.imshow(img1, cmap='gray')
plt.title('skimage read')
plt.xticks([])
plt.yticks([])
plt.subplot(2, 2, 2)
plt.imshow(img2, cmap='gray')
plt.title('cv2 read')
plt.xticks([])
plt.yticks([])
plt.subplot(2, 2, 3)
h = np.histogram(img1, 100)
plt.plot(h[0])
plt.title('skimage read histogram')
plt.subplot(2, 2, 4)
h = np.histogram(img2, 100)
plt.plot(h[0])
plt.title('cv2 read histogram')
plt.show()
Text Output:文本输出:
(512, 512) (512, 512)
Output:输出:
Edit:编辑:
Here is the input image:这是输入图像:
The two imread
functions just have a different default format for reading the images.这两个imread
函数只是具有不同的默认格式来读取图像。 The skimage.io
standard is using a 64-bit float, while the cv2
standard seems to be unsigned byte. skimage.io
标准使用 64 位浮点数,而cv2
标准似乎是无符号字节。
You can see this by converting img1
to the unsigned byte format.您可以通过将img1
转换为无符号字节格式来查看这一点。
import skimage as skk
img1 = skk.img_as_ubyte(img1)
Now you will get somewhat similar histograms.They are not perfectly the same because they are read initially as different formats.现在您将得到有些相似的直方图。它们并不完全相同,因为它们最初被读取为不同的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.