【问题标题】:Coloring a grayscale 16 bit image为灰度 16 位图像着色
【发布时间】:2017-07-31 21:22:53
【问题描述】:

我想为 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' )

这只是图像显示方式的一个示例,每个示例中的黑色都不清晰。 i不是我在代码中的形象。

【问题讨论】:

  • 红色区域内的值是NaN的吗?
  • 这只是一个例子它不是我在代码中的形象。没有红色区域内的值不是NaN的
  • 你想用什么方法或基础上色?对于梯度映射,您需要处理最小值和最大值,在某些情况下还需要处理值的分布(因此您可以选择线性或非线性映射)。
  • 我想使用 RGB 基础上色
  • @RabihAssaf 你误解了着色的基础我的意思是你想如何从值计算颜色(不是你需要的颜色空间)有很多方法,比如 1. 得到预定义的颜色渐变,然后映射到你的值(如 IR 相机图像) 2. 值具有绑定到特定颜色的特定物理属性(如可见光谱波长,或 star BV) 3. 您想要唯一值的唯一颜色 4. 想要强调一些数学或物理属性数组等有太多的可能性,所以更接近你想要的。

标签: python image image-processing colors grayscale


【解决方案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' )

但是,如果我将上面的示例更改为使用 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' )

我确实认为,当给出大于 1 的值时,它只会在除以 1 时考虑其余数(您可以通过更改最后一个示例中的 image = ((b+c)/2)%1 行并验证您得到相同的图像来检查这一点)。

【讨论】:

    猜你喜欢
    • 2020-05-02
    • 2017-08-07
    • 2011-11-23
    • 1970-01-01
    • 2015-07-01
    • 2012-05-28
    • 2015-08-11
    • 2015-06-29
    相关资源
    最近更新 更多