skimage.io.imread与cv2.imread [英] skimage.io.imread Versus cv2.imread

查看:218
本文介绍了skimage.io.imread与cv2.imread的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用并熟悉 cv2 ,今天我尝试使用 skimage

I am using and familiar with cv2, today I was giving a try with skimage.

我试图使用 skimage cv2 读取图像。看来他们俩都能完美阅读图像。但是当我绘制图像的直方图但通过不同的库( skimage cv2 )读取时,直方图显示出

I was trying to read an image using skimage and 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.

有人会通过解释直方图之间的差异来帮助我吗?

Would anyone help me by explaining the difference between the histograms?

我的代码:

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()

文本输出:


(512, 512)
(512, 512)

输出:




编辑:

以下是输入图像:

推荐答案

这两个 imread 函数只是具有用于读取图像的默认格式。 skimage.io 标准使用的是64位浮点数,而 cv2 标准似乎是无符号字节。 br>
您可以通过将 img1 转换为无符号字节格式来看到它。

The two imread functions just have a different default format for reading the images. The skimage.io standard is using a 64-bit float, while the cv2 standard seems to be unsigned byte.
You can see this by converting img1 to the unsigned byte format.

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.

这篇关于skimage.io.imread与cv2.imread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆