2017-03-10 344 views
-2

我想对16位灰度图像(其最大值为850)的某些像素着色。 首先,我把它变成了一个3d堆栈(I),然后我通过了一个颜色 ,但图像没有出现在一个好的方式。着色灰度16位图像

I = np.dstack([image, image, image]) 
    I[5:10, 5:10, :] = [200, 0 , 0] 
    plt.figure() 
    plt.imshow(I, interpolation='nearest') 

the 16 bits grayscale image after the colour changing edited 这只是图像的显示为例,黑色是不是在所有每例子清楚。我不是代码中的我的形象。

+0

红色区域'NaN'的值是? – berna1111

+0

这只是一个例子,它不是代码中我的形象。否红色区域内的值不是NaN的 –

+0

您想要着色的方法或基础是什么?对于渐变映射,您需要处理最小值和最大值,在某些情况下还需要处理值分布(以便您可以选择线性映射或非线性映射)。 – Spektre

回答

1

您确定RGB值介于0和1之间吗?使用你的代码,我做了这个例子:

import matplotlib.pyplot as plt 
import numpy as np 

n_points = 100 
a = np.linspace(0, 1, n_points) 
b,c = np.meshgrid(a,a) 
image = (b+c)/2 

a_third = n_points/3. 

I = np.dstack([image, image, image])# 
I[a_third:2*a_third, a_third:2*a_third, :] = [1 , 0 , 0] 
plt.figure() 
plt.imshow(I, interpolation='nearest') 

Resulting picture with the centre in red

但是,如果我改变上面的例子中使用0到255之间的值(你似乎那些点设置为[200, 0, 0]时做):

import matplotlib.pyplot as plt 
import numpy as np 

n_points = 100 
a = np.linspace(0, 255, n_points) 
b,c = np.meshgrid(a,a) 
image = (b+c)/2 

a_third = n_points/3. 

I = np.dstack([image, image, image])# 
I[a_third:2*a_third, a_third:2*a_third, :] = [255 , 0 , 0] 
plt.figure() 
plt.imshow(I, interpolation='nearest') 

enter image description here

给出的值大于1时,只会考虑其剩余W¯¯当我认为母鸡除以1(你可以在最后一个例子中通过更改image = ((b+c)/2)%1行来检查,并验证你获得了相同的图像)。