pyplot显示不正确,图像太暗 [英] Bad display with pyplot, image too dark
本文介绍了pyplot显示不正确,图像太暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理图像处理问题.
I am working on an image processing problem.
我创建了一个将盐和胡椒粉噪点应用到图像的函数. 功能如下:
I create a function that applies a salt and pepper noise to an image. Here is the function:
def sp_noise(image,prob):
res = np.zeros(image.shape,np.uint8)
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn < prob:
rdn2 = random.random()
if rdn2 < 0.5:
res[i][j] = 0
else:
res[i][j] = 255
else:
res[i][j] = image[i][j]
return res
我想显示结果时出现问题.
Problems happen when I want to display the result.
wood = loadPNGFile('wood.jpeg',rgb=False)
woodSP = sp_noise(bois,0.01)
plt.subplot(1,2,1)
plt.imshow(bois,'gray')
plt.title("Wood")
plt.subplot(1,2,2)
plt.imshow(woodSP,'gray')
plt.title("Wood SP")
我无法直接发布图片,但这是链接:
I can not post the image directly but here is the link:
图片较暗.但是当我显示像素值时
The picture is darker. But when I display the value of the pixels
但是当我显示两幅图像之间的像素值时,它们的值是相同的:
But when I display the value of the pixels between the 2 images the values are the same:
[[ 99 97 96 ... 118 90 70]
[110 110 103 ... 116 115 101]
[ 79 73 65 ... 96 121 121]
...
[ 79 62 46 ... 105 124 113]
[ 86 98 100 ... 114 119 99]
[ 96 95 95 ... 116 111 90]]
[[255 97 96 ... 118 90 70]
[110 110 103 ... 116 115 101]
[ 79 73 65 ... 96 121 121]
...
[ 79 62 46 ... 105 124 113]
[ 86 98 100 ... 114 119 99]
[ 96 95 95 ... 116 111 90]]
我还要检查平均值:
117.79877369007804
117.81332616658703
显然问题出在显示器plt.imshow,但我找不到解决方法
Apparently the problem comes from the display plt.imshow, but I can not find a solution
推荐答案
查看全文