I have some code that prints out a list of coordinates (stored in points
f=open('139cm_2000_frame27.json')
data=json.load(f)
shapes=data["shapes"]
for i in shapes:
print(i['label']) # prints the label first
for c in i['points']:
d=np.array(c)
print(d) # an array containing coordinates in the form (x,y)
d, the coordinates, are the points of n number of 10 sided polygons. So coordinates 0-9 are the coordinates of the first polygon, coordinates 10-19 are the second polygon...
There could be any number of polygons in the json file but they will each, always, have 10 coordinates.
I need to find a way of using those coordinates to 'draw'/'recreate' these polygons in a 128x128 array.
I have tried
from skimage.draw import polygon
img = np.zeros((128, 128), dtype=np.uint8)
r = np.array([#the x coordinates of d])
c = np.array([#the y coordinates of d])
rr, cc = polygon(r, c)
img[rr, cc] = 1 #unsure about the 1
img
but I do not know how to 1) get sets of 10 coordinates and 2) read the xs into r and the ys into c
Thank you so much!
An example of the input json:
{
"version": "4.6.0",
"flags": {},
"shapes": [
{
"label": "blob",
"points": [
[
61.42857142857143,
20.285714285714285
],
[
59.10047478151446,
18.879430437885873
],
[
58.04359793578868,
16.37330203102605
],
[
58.661631924538575,
13.724584936383643
],
[
60.71850877026435,
11.94499905752918
],
[
63.42857142857143,
11.714285714285715
],
[
65.75666807562841,
13.120569562114127
],
[
66.81354492135418,
15.62669796897395
],
[
66.19551093260428,
18.275415063616357
],
[
64.13863408687851,
20.05500094247082
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "blob",
"points": [
[
88.71428571428572,
82.42857142857143
],
[
85.63470409582908,
81.33512050565437
......