【问题标题】:Make a color grid with different colors for each index为每个索引制作不同颜色的颜色网格
【发布时间】:2021-01-02 23:53:42
【问题描述】:

理想情况下,使用 Numpy 和 PIL,我想为我正在制作的图像分割程序制作一个颜色网格。并非所有颜色都必须是唯一的,但是,每种颜色都应该与其相邻颜色不同并且可以识别其位置。这个想法是创建一个叠加层,可以快速识别每个像素的 x,y 位置坐标。图片为 250x250。

【问题讨论】:

  • 你能澄清一些问题吗?如果颜色不是唯一的(即一种颜色可能出现在多个位置),如何识别颜色的位置 - 它肯定可以在多个位置?你提到了一个 "overlay" - 一个覆盖/为了什么?我的意思是你打算如何使用它?谢谢。
  • 嗨,马克,我的意思是,对于整个图像,每种颜色不必是唯一的 - 根据模糊的位置和颜色,您可以知道每个像素的 x、y 坐标。
  • 对于我将如何使用它,我将显示包含多个对象的图像,“像素网格”覆盖图像。通过像素叠加,我可以手动记下每个对象的边界框像素的 x、y 位置,只需查看图像即可。

标签: python numpy colors python-imaging-library linspace


【解决方案1】:

好吧,我搞砸了,想出了这样的东西:

import PIL.Image

def zoom(img, zoom):
    w, h = img.size
    print(w,h)
    zoom2 = zoom * 2
    return img.resize((w*zoom, h*zoom), PIL.Image.NEAREST)

green = 0
red = 0
blue = 0

img = np.zeros([10,10,3], dtype=np.uint8)

for i in range(10):
    green += 52
    blue += 45
    green %= 256
    blue %= 256
    img[i,:,1:] = [blue,green]
    
blue = 0
for j in range(10):
    red += 47
    blue += 48
    red %= 256
    blue %= 256
    img[:,j,0] = red
    img[:,j,2] = blue

grid = np.tile( img, [5, 5, 1])
grid = grid.astype(np.uint8)
zoom(PIL.Image.fromarray(grid), 8)

导致这张图片:

这只会生成 50x50 的网格,但在较大的图像上很难看到网格。我可能会尝试以另一种方式执行我的分段程序。这样做的一个好处是,您可以通过注释掉设置 x 颜色值的代码或设置 y 颜色值的代码来“调试”一半颜色。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-16
  • 2022-01-24
  • 1970-01-01
  • 2011-09-02
  • 2013-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多