Skip to content

Commit

Permalink
Segmentation palette modifications (#3053)
Browse files Browse the repository at this point in the history
* Segmentation palette modifications

* Embed color profile for palette
  • Loading branch information
Sai Vemprala authored Oct 2, 2020
1 parent 40d5efb commit f423d9f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy
import random

# requires Python 3.5.3 :: Anaconda 4.4.0
# pip install opencv-python
import cv2
Expand All @@ -13,24 +14,35 @@ def generate_color_palette(numPixelsWide, outputFile):
possibilities = [list(range(256)), list(range(256)), list(range(256))]

colors = [[0] * 3 for i in range(256)]


choice = 0
j = 0
for i in range(3):
palette[0, j * numPixelsWide : (j + 1) * numPixelsWide, i] = choice
colors[j][i] = choice

for i in range(3):
for j in range(256):
for j in range(1, 255):
choice = random.sample(possibilities[i], 1)[0]
possibilities[i].remove(choice)
palette[0, j * numPixelsWide:(j + 1) * numPixelsWide, i] = choice
palette[0, j * numPixelsWide : (j + 1) * numPixelsWide, i] = choice
colors[j][i] = choice

cv2.imwrite(outputFile, palette, [cv2.IMWRITE_PNG_COMPRESSION,0])
choice = 255
j = 255
for i in range(3):
palette[0, j * numPixelsWide : (j + 1) * numPixelsWide, i] = choice
colors[j][i] = choice

cv2.imwrite(outputFile, palette, [cv2.IMWRITE_PNG_COMPRESSION, 0])

rgb_file = open("rgbs.txt", "w")
for j in range(256):
rgb_file.write("%d\t%s\n" % (j, str(list(reversed(colors[j])))))
rgb_file.close()


if __name__ == '__main__':

if __name__ == "__main__":
numPixelsWide = 4
outputFile = 'seg_color_pallet.png'
generate_color_palette(numPixelsWide, outputFile)
outputFile = "seg_color_palette.png"
generate_color_palette(numPixelsWide, outputFile)
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/seg_rgbs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0 [55, 181, 57]
0 [0, 0, 0]
1 [153, 108, 6]
2 [112, 105, 191]
3 [89, 121, 72]
Expand Down Expand Up @@ -253,4 +253,4 @@
252 [130, 56, 55]
253 [147, 210, 11]
254 [162, 203, 118]
255 [43, 47, 206]
255 [255, 255, 255]

0 comments on commit f423d9f

Please sign in to comment.