matplotlib中的低对比度图像(对比度拉伸)问题 [英] problems low contrast image(contrast stretching) in matplotlib

查看:337
本文介绍了matplotlib中的低对比度图像(对比度拉伸)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在读取低对比度图像时,它会自动以以下示例为例:

When reading a low-contrast image it automatically take this example:

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

输入

绘图(matplotlib不会自动更改.)

Plot (no change this is automatic by matplotlib.)

因为此输入与不进行任何修改的绘图不同.

Because this input is different from the plot without, modifying anything.

我需要低对比度的图像才能实现对比度拉伸的算法

I need low-contrast image to implement an algorithm to contrast stretching

阅读本书 amazon 数字图像处理(拉斐尔·冈萨雷斯(Rafael C. Gonzalez),理查德·E·伍兹(Richard E. Woods))

Reading the book amazon Digital Image Processing (Rafael C. Gonzalez, Richard E. Woods)

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

PS: matplotlib is converting the automatic. I do not need.

推荐答案

如果不希望自动缩放颜色图,则可以使用vminvmax设置所需的范围,如下所示:

If you do not want the automatic scaling of the colormap, you can use vmin and vmax to set the range you prefer, like this:

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

在显示一个numpy数组时,matplotlib只能自动知道实际输入数据的范围(而不是它取自的范围),因此它需要完整的 input 范围并将其映射到完整的输出范围.但是,如果您知道输入数据的不同范围,则可以使用vminvmax进行指定.

When showing a numpy array, matplotlib can only automatically know the range of the actual input data (not the range it was taken from), so it takes the full input range an maps it to the full output range. But if you know a different range of the input data, you can use vmin and vmax to specify it.

这篇关于matplotlib中的低对比度图像(对比度拉伸)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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