Ideally using Numpy and PIL, I'd like to make a grid of colors for a image segmentation program I'm making. Not all of the colors have to be unique, but, each color should be distinct from its neighbors and recognizable for its position. The idea is to create an overlay for which each pixel's x,y position coordinates can be quickly discerned. The images are 250x250.
Asked
Active
Viewed 461 times
2
-
1Could you clarify some points please? If the colours are not unique (i.e. one colour could occur at multiple places), how can a colour be recognizable for its position - surely it could be at multiple positions? You mention an *"overlay"* - an overlay of/for what? I mean how do you plan to use it? Thank you. – Mark Setchell Sep 16 '20 at 08:28
-
Hi Mark, I meant that each color doesn't have to be unique for the whole image - based on the vague location and the color, you could tell the x,y coordinates of every pixel. – chenjesu Sep 16 '20 at 08:41
-
For how I am going to use it, I would display image with multiple objects in it, with the "pixel grid" overlaying the image. From the pixel overlay, I could manually write down the x,y location of the bounding box pixels for each object, just by looking at the image. – chenjesu Sep 16 '20 at 08:43
1 Answers
2
Okay, I messed around with it and came up with something like this:
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)
Resulting in this picture:
This only makes a 50x50 grid, but it's pretty hard to see the grid on a larger image. I might try doing my segmentation program another way. One nice thing about this is that you can "debug" half of the colors by commenting out either the code that sets the x color values, or the code that sets the y color values.

chenjesu
- 734
- 6
- 14
-
1Cool. You may find this article about HALD CLUTs interesting http://www.quelsolaar.com/technology/clut.html – Mark Setchell Sep 16 '20 at 09:06