【问题标题】:How can I change a grayscale pixel value by a colored value given the value of the pixel not the coordinate给定像素值而不是坐标,如何通过彩色值更改灰度像素值
【发布时间】:2019-03-05 00:24:49
【问题描述】:

在给定像素值而不是坐标的情况下,我想通过彩色值更改灰度像素值。 给定坐标我知道该怎么做:

I = np.dstack([im, im, im])
x = 5
y = 5
I[x, y, :] = [1, 0, 0]
plt.imshow(I, interpolation='nearest' )

但是如何在像 I[im == 10] = [1, 0 ,0] 这样的值中做到这一点 不工作。

【问题讨论】:

  • I[im == 5] 是什么意思?您想将 所有 像素(例如 [1,0,0])更改为 [200,0,0] 吗?
  • 我编辑问题:我想将所有等于 10 的像素更改为红色值 [1,0,0]。

标签: python image image-processing grayscale


【解决方案1】:

我建议这样做,虽然它可能很脏:

while [10,10,10] in I:
    I[I.index([10,10,10])] = [1,0,0]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 2013-04-05
    • 2012-06-01
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多