使用python imshow显示“Haze”或“fog”为什么黑色区域看起来是灰色的?

2024-10-04 03:19:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望这是一个非常直截了当的问题。我正在处理从FITS文件读入的一些图像到numpy数组中。我想做一个RGB图像。问题是,当我制作RGB图像时,似乎会出现这种“白色薄雾”。或者,我知道在这张图片中黑色的区域应该是黑色的,但是它们看起来是灰色的。G图像中的果岭非常漂亮。整个图像看起来像是有白色的薄雾或雾。我想也许是设置阿尔法的问题?注:将RBGA中的A设置为0和255对问题没有帮助。在

这是一个图像示例——我会展示它,除非我没有足够的声誉点数。不幸的是,在这种情况下,一张照片抵得上1000个字。。。在

下面是我用来处理图像的代码:

testrgb = np.zeros([512,512,4])
# 
# converting read in image to float
tmpr = asi1r.astype('float')
tmpg = asi1g.astype('float')
tmpb = asi1b.astype('float')


#http://akash0x53.github.io/blog/2013/04/29/normalization/ pretty obvious
tmptotal = tmpr+tmpg+tmpb
R = tmpr/tmptotal
G = tmpg/tmptotal
B = tmpb/tmptotal

# eliminate the nans in the division
R[np.isnan(R) == True] = 0.
G[np.isnan(G) == True] = 0.
B[np.isnan(B) == True] = 0.

testrgb[:,:,0] = R*255.
testrgb[:,:,1] = G*255. #asi1g.astype('float')
testrgb[:,:,2] = B*255. #asi1b.astype('float')
testrgb[:,:,3] = 255.

testrgb = testrgb.astype('uint8')

f = plt.figure(figsize=(4,4), dpi=300)
plt.imshow(testrgb,cmap='jet',vmin=0,vmax=200)
plt.colorbar()
plt.show()
f.savefig('test.png')
plt.close('all')

任何帮助都将不胜感激。非常感谢。在


Tags: 图像truenppltrgbfloat白色astype
1条回答
网友
1楼 · 发布于 2024-10-04 03:19:54

这似乎不是matplotlib的问题。从你的评论看来,正常化的确是错误的。尝试以下操作:

tmptotal = tmpr + tmpg + tmpb
testrgb[..., 0] = tmpr 
testrgb[..., 1] = tmpg 
testrgb[..., 2] = tmpb 

testrgb *= (255.*3) / tmptotal

imshow(testrgb, cmap='jet')

vmaxvmin设置不适用于RGB图像。在

相关问题 更多 >