matplotlib.pyplot.imshow如何神奇地处理超过255个像素的值?

时间:2018-11-15 11:44:15

标签: python opencv matplotlib overflow

最近我一直在与matplotlib一起处理图像。

我发现有趣的是,“ matplotlib.pyplot.imshow”似乎可以工作

神奇的问题是,如果您的像素值大于255,则在opencv中具有功能

imshow将完全弄乱图像

这是我尝试的:

import cv2 as cv
import numpy as np 
import matplotlib.pyplot as plt
img=cv.imread("image1.jpg",cv.IMREAD_GRAYSCALE) 
img
array([[ 69,  69,  68, ..., 191, 184, 180],
    [ 65,  65,  65, ..., 197, 191, 188],
    [ 61,  61,  62, ..., 200, 197, 195],
    ...,
    [ 75,  73,  73, ...,  96,  88,  65],
    [ 84,  80,  76, ..., 145, 135, 111],
    [ 90,  82,  73, ..., 216, 215, 217]], dtype=uint8)
img=img.astype(np.int32)
img+=500
plt.imshow(img, cmap="gray")
plt.show()
>>>img
array([[567, 567, 566, ..., 689, 682, 678],
    [563, 563, 563, ..., 695, 689, 686],
    [559, 559, 560, ..., 698, 695, 693],
    ...,
    [573, 571, 571, ..., 594, 586, 563],
    [582, 578, 574, ..., 643, 633, 609],
    [588, 580, 571, ..., 714, 713, 715]], dtype=int32)

最后,您会发现数组实际上没有更改

但是它可以提供完美的原始图像

我想知道他们如何处理这个问题,谢谢!

0 个答案:

没有答案