gpt4 book ai didi

python - matplotlib 中的低对比度图像(对比度拉伸(stretch))问题

转载 作者:行者123 更新时间:2023-11-28 20:23:50 27 4
gpt4 key购买 nike

当读取低对比度图像时,它会自动采用以下示例:

In [1]: from PIL import Image
In [2]: import numpy as np
In [3]: import matplotlib.pyplot as plt
In [4]: img = Image.open('images/map.jpg')
In [5]: arr = np.asarray(img)
In [6]: plt.gray()
In [7]: plt.imshow(arr)
Out[7]: <matplotlib.image.AxesImage at 0x7f9c7e88f490>
In [8]: plt.show()

输入

input large

绘图(没有变化,这是 matplotlib 自动完成的。)

plot large

因为这个输入与没有修改任何东西的情节不同。

我需要低对比度图像来实现对比度拉伸(stretch)算法

看书amazon数字图像处理(Rafael C. Gonzalez、Richard E. Woods)

PS:matplotlib 正在转换 自动。我不需要。

最佳答案

如果您不想自动缩放颜色图,可以使用 vminvmax 设置您喜欢的范围,如下所示:

plt.imshow(arr, vmin=0, vmax=255)

当显示一个 numpy 数组时,matplotlib 只能自动知道实际输入数据的范围(而不是从中获取的范围),因此它采用完整的输入范围并将其映射到完整的输出范围。但是,如果您知道输入数据的不同范围,则可以使用 vminvmax 来指定它。

关于python - matplotlib 中的低对比度图像(对比度拉伸(stretch))问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836615/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com