Skip to content
Snippets Groups Projects
Commit 6d25f9e6 authored by Klein, Roel's avatar Klein, Roel
Browse files

formatting

parent 5dd9b7b0
No related branches found
No related tags found
1 merge request!1Evaluation update
...@@ -4,21 +4,22 @@ import pycocotools.mask ...@@ -4,21 +4,22 @@ import pycocotools.mask
def x1y1x2y2_2_x1x2y1y2(this_list): def x1y1x2y2_2_x1x2y1y2(this_list):
new_list = [0]*4 new_list = [0] * 4
new_list[0] = this_list[0] new_list[0] = this_list[0]
new_list[1] = this_list[2] new_list[1] = this_list[2]
new_list[2] = this_list[1] new_list[2] = this_list[1]
new_list[3] = this_list[3] new_list[3] = this_list[3]
return new_list return new_list
def x1x2y1y2_2_x1y1x2y2(this_list): def x1x2y1y2_2_x1y1x2y2(this_list):
new_list = [0]*4 new_list = [0] * 4
new_list[0] = this_list[0] new_list[0] = this_list[0]
new_list[1] = this_list[2] new_list[1] = this_list[2]
new_list[2] = this_list[1] new_list[2] = this_list[1]
new_list[3] = this_list[3] new_list[3] = this_list[3]
return new_list return new_list
def xywh2xyxy_yolo(x): def xywh2xyxy_yolo(x):
y = np.copy(x) y = np.copy(x)
...@@ -29,15 +30,15 @@ def xywh2xyxy_yolo(x): ...@@ -29,15 +30,15 @@ def xywh2xyxy_yolo(x):
return y return y
def xywh2xxyy(list_input): def xywh2xxyy(list_input):
this_list = list_input.copy() this_list = list_input.copy()
this_list[0] = list_input[0] # x1 this_list[0] = list_input[0] # x1
this_list[1] = list_input[0] + list_input[2] # x2 this_list[1] = list_input[0] + list_input[2] # x2
this_list[2] = list_input[1] # y1 this_list[2] = list_input[1] # y1
this_list[3] = list_input[1] + list_input[3] # y2 this_list[3] = list_input[1] + list_input[3] # y2
return this_list return this_list
def xywh2xyxy(list_input): def xywh2xyxy(list_input):
this_list = list_input.copy() this_list = list_input.copy()
this_list[2] = list_input[0] + list_input[2] this_list[2] = list_input[0] + list_input[2]
...@@ -46,56 +47,74 @@ def xywh2xyxy(list_input): ...@@ -46,56 +47,74 @@ def xywh2xyxy(list_input):
this_list[1] = list_input[1] this_list[1] = list_input[1]
return this_list return this_list
def xyxy2xywh(list_input):
x1 = int(list_input[0]) def xyxy2xywh(listinput):
y1 = int(list_input[1]) x1 = int(listinput[0])
w = abs(int(list_input[2]-list_input[0])) y1 = int(listinput[0])
h = abs(int(list_input[3]-list_input[1])) w = int(listinput[2] - listinput[0])
return [x1,y1,w,h] h = int(listinput[3] - listinput[1])
assert w > 0
assert h > 0
return [x1, y1, w, h]
def xywh_2_x1y1x2y2(list_input): def xywh_2_x1y1x2y2(list_input):
x1 = int(list_input[0]) x1 = int(list_input[0])
y1 = int(list_input[1]) y1 = int(list_input[1])
x2 = int(x1 + list_input[2]) x2 = int(x1 + list_input[2])
y2 = int(y1 + list_input[3]) y2 = int(y1 + list_input[3])
return [x1,y1,x2,y2] return [x1, y1, x2, y2]
def x1y1x2y2_2_cxcywh(list_input,height_img, width_img): def x1y1x2y2_2_cxcywh(list_input, height_img, width_img):
# conversin of [x1,y1,x2,y2] to normalized yolo! [center_x,center_y,width,height] # conversin of [x1,y1,x2,y2] to normalized yolo! [center_x,center_y,width,height]
center_x = (list_input[0]+list_input[2])/2 center_x = (list_input[0] + list_input[2]) / 2
center_y = (list_input[1]+list_input[3])/2 center_y = (list_input[1] + list_input[3]) / 2
width = (list_input[2]-list_input[0]) width = list_input[2] - list_input[0]
height = (list_input[3]-list_input[1]) height = list_input[3] - list_input[1]
return [center_x/width_img,center_y/height_img,width/width_img,height/height_img] return [
center_x / width_img,
def x1y1wh_2_cxcywh(list_input,height_img, width_img): center_y / height_img,
# conversin of [x1,y1,x2,y2] to normalized yolo! [center_x,center_y,width,height] width / width_img,
center_x = (list_input[0]+list_input[2]*0.5) height / height_img,
center_y = (list_input[1]+list_input[3]*0.5) ]
width = list_input[2]
height = list_input[3]
return [center_x/width_img,center_y/height_img,width/width_img,height/height_img] def x1y1wh_2_cxcywh(list_input, height_img, width_img):
# conversin of [x1,y1,x2,y2] to normalized yolo! [center_x,center_y,width,height]
center_x = list_input[0] + list_input[2] * 0.5
center_y = list_input[1] + list_input[3] * 0.5
width = list_input[2]
height = list_input[3]
return [
center_x / width_img,
center_y / height_img,
width / width_img,
height / height_img,
]
def binary_mask_to_rle(binary_mask): def binary_mask_to_rle(binary_mask):
## input is numpy array with either 0 or 1 : np.array([0,0,1,1,1,0,1]) ## input is numpy array with either 0 or 1 : np.array([0,0,1,1,1,0,1])
## output: rle={'counts': [2, 3, 1, 1], 'size': [7]} ## output: rle={'counts': [2, 3, 1, 1], 'size': [7]}
rle = {'counts': [], 'size': list(binary_mask.shape)} rle = {"counts": [], "size": list(binary_mask.shape)}
counts = rle.get('counts') counts = rle.get("counts")
for i, (value, elements) in enumerate(groupby(binary_mask.ravel(order='F'))): for i, (value, elements) in enumerate(groupby(binary_mask.ravel(order="F"))):
if i == 0 and value == 1: if i == 0 and value == 1:
counts.append(0) counts.append(0)
counts.append(len(list(elements))) counts.append(len(list(elements)))
return rle return rle
def rle_to_binary_mask(rle): def rle_to_binary_mask(rle):
## converts rle={'counts': [2, 3, 1, 1], 'size': [7]} to np.array([0,0,1,1,1,0,1]) ## converts rle={'counts': [2, 3, 1, 1], 'size': [7]} to np.array([0,0,1,1,1,0,1])
compressed_rle = pycocotools.mask.frPyObjects(rle, rle.get('size')[0], rle.get('size')[1]) compressed_rle = pycocotools.mask.frPyObjects(
mask = pycocotools.mask.decode(compressed_rle) rle, rle.get("size")[0], rle.get("size")[1]
return mask )
mask = pycocotools.mask.decode(compressed_rle)
return mask
def box2centroid(b): def box2centroid(b):
centroid = [int((b[2]+b[0])/2), int((b[3]+b[1])/2)] centroid = [int((b[2] + b[0]) / 2), int((b[3] + b[1]) / 2)]
return centroid return centroid
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment