简体   繁体   中英

problems low contrast image(contrast stretching) in 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()

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM