panel_disconnet

This commit is contained in:
Daniel Saavedra
2020-03-25 09:43:11 -03:00
parent dce4a1a2c3
commit 7010af8a58
2 changed files with 43 additions and 36 deletions

View File

@@ -7,7 +7,7 @@ Created on Tue Mar 17 13:55:42 2020
"""
import numpy as np
def disconnect(image, boxes, obj_thresh = 0.5, area_min = 400, merge = 0):
def disconnect(image, boxes, obj_thresh = 0.5, area_min = 400, merge = 0, z_thresh = 1.8):
new_boxes = []
for num, box in enumerate(boxes):
@@ -17,25 +17,25 @@ def disconnect(image, boxes, obj_thresh = 0.5, area_min = 400, merge = 0):
ymin = box.ymin + merge
ymax = box.ymax - merge
if xmin > 0 and ymin > 0 and xmax < image.shape[1] and ymax < image.shape[0] and box.classes[0] > obj_thresh:
if xmin > 0 and ymin > 0 and xmax < image.shape[1] and ymax < image.shape[0] and box.get_score() > obj_thresh:
area = (ymax - ymin)*(xmax - xmin)
z_score = np.sum(image[np.int(ymin):np.int(ymax), np.int(xmin):np.int(xmax)]) / area
if area > area_min:
box.score = z_score
box.z_score = z_score
new_boxes.append(box)
#boxes_area_score[str(num)] = {'xmin': xmin, 'xmax': xmax, 'ymin': ymin, 'ymax': ymax, 'score' : score, 'area' : area}
mean_score = np.mean([box.score for box in new_boxes])
sd_score = np.std([box.score for box in new_boxes])
mean_score = np.mean([box.z_score for box in new_boxes])
sd_score = np.std([box.z_score for box in new_boxes])
new_boxes = [box for box in new_boxes if (box.score - mean_score)/sd_score > 2]
new_boxes = [box for box in new_boxes if (box.z_score - mean_score)/sd_score > z_thresh]
for box in new_boxes:
z_score = (box.score - mean_score)/sd_score
box.classes[0] = min((z_score-2)*0.5+ 0.5, 1)
z_score = (box.z_score - mean_score)/sd_score
box.classes[0] = min((z_score-z_thresh)*0.5/(3-z_thresh)+ 0.5, 1)
return new_boxes