problems low contrast image(contrast stretching) in matplotlib

♀尐吖头ヾ 提交于 2020-01-01 17:25:53

问题


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

Input

large

Plot (no change this is automatic by matplotlib.)

large

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

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

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

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


回答1:


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)

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.



来源:https://stackoverflow.com/questions/18836615/problems-low-contrast-imagecontrast-stretching-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!