着色灰度16位图像

时间:2017-03-10 13:49:45

标签: python image image-processing colors grayscale

我想为16位灰度图像(最大值为850)的某些像素着色。 首先,我将它转换为3d堆栈(I),然后我传递了一种颜色 对它而言,图像并没有以良好的方式出现。

   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 这只是图像出现的一个例子,黑色在每个例子中都不清楚。我不是代码中的I形象。

1 个答案:

答案 0 :(得分: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的值时,它只会在除以1时考虑其余数(您可以通过更改上一个示例中的行image = ((b+c)/2)%1并验证您获得相同的图像来检查这一点)。