I am using this code
with open('frame 0001.json') as json_file:
json_dict = json.load(json_file)
shape = (1920, 1052)
canvas = np.zeros(shape)
for obj in json_dict["objects"]:
pts = [((round(p["x"] - 1)), (round(p["y"]))) for p in obj["polygon"]]
mp.fill_polygon(pts, canvas, obj["classIndex"])
pic = canvas.transpose()
plt.imshow(pic)
plt.show()
to convert an JSON file into a plot. However, I would like to change the colors which are first set by obj["classIndex"]
to another color. While printing the plot, I found out that the plot looks like this
[[5. 5. 5. 5.]
[5. 5. 5. 5.]
[5. 5. 5. 5.]
...
[4. 4. 4. 4.]
[4. 4. 4. 4.]
[0. 0. 0. 0.]]
I have never seen this before. how would I go about to change these values into RGBs? That I set before. I know I could use
colors = [
(0, 0, 0, 255),
(100, 100, 100, 255),
(204, 0, 0, 255),
(0, 174, 0, 255),
(102, 51, 153, 255),
(0, 0, 155, 255),
(255, 102, 0, 255),
for idx, c in enumerate(colors):
pic[np.all(pic == idx)] = c
to change something like this
[[0 0 0 0]
[0 0 0 0]
[0 0 0 0]]
to this
[[0 0 0 255]
[0 0 0 255]
[0 0 0 255]
[0 0 0 255]]
however, I have never worked with something like this before
[[5. 5. 5. 5.]
[5. 5. 5. 5.]
[5. 5. 5. 5.]]