Imread 灰度与 imread + 不同转换为灰度
在使用 OpenCV 时,我发现了一种奇怪的行为,而我的知识无法解释它。 或许有人会有答案。
image= cv.imread("image.jpg", 0)
__, thre = cv.threshold(image, 1, 255, cv.THRESH_BINARY)
plt.imshow(thre)
image = cv.imread("image.jpg")
image= cv.cvtColor(output, cv.COLOR_BGR2GRAY)
__, thre = cv.threshold(image, 1, 255, cv.THRESH_BINARY)
plt.imshow(thre)
正如您所看到的,这两个图像有点不同。 有人可以解释一下为什么使用带标志 0(灰度)的 imread 会产生与使用不带标志的 imread 并在之后将其转换为灰度的结果不同的结果。
是因为 cvtColor 标志吗?
While working with OpenCV, I found a curious behavior and my knoledge couldn't explain it.
Maybe someone will have the answer.
image= cv.imread("image.jpg", 0)
__, thre = cv.threshold(image, 1, 255, cv.THRESH_BINARY)
plt.imshow(thre)
image = cv.imread("image.jpg")
image= cv.cvtColor(output, cv.COLOR_BGR2GRAY)
__, thre = cv.threshold(image, 1, 255, cv.THRESH_BINARY)
plt.imshow(thre)
As you can see, the two images are a bit different.
Could someone explain me why using imread with flag 0 (grayscale) make a different result than using imread without a flag and convert it to grayscale after.
Is it because of the cvtColor flag ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您观察到的效果的原因,但我想指出,存在两种不同的方式 RGB 到灰度转换:即使用均值和加权平均值,在后面的情况下可能会使用不同的权重,据说
cvtColor()
使用以下公式,链接文章中还提供了另一个公式,其权重根据人类感知进行调整,如下所示
请注意,由于上述转换是幂等的,您可能会不小心将已经灰度图像输入其中。
I am not sure if this is reason for effect you have observed, but I want to note that there exist two distinct ways of RGB to Grayscale Conversion: that is using mean and using weighted average, in later case different weights might be used,
cvtColor()
is said to use following formulathere is also another formula provided in linked article with weights adjusted for human perception as follows
Note that as above transformations are idempotent you might feed already grayscale image into them without care.