def clean_segmentation2(segments, img_size):
seg_binary = np.zeros_like(segments)
for i in xrange(segments.shape[0]):
_,sb = cv2.threshold(np.copy(segments[i,0])*255, 127, 255, cv2.THRESH_BINARY)
patches = get_patches(sb)
if len(patches)==0:
continue
sum_pdf_vals = [sum(pdf_dict[x,y] for x,y in p) for p in patches]
avg_pdf_vals = [sum(pdf_dict[x,y] for x,y in p)/p.shape[0] for p in patches]
max_sum_pdf = max(sum_pdf_vals)
for p_idx, p in enumerate(patches):
if avg_pdf_vals[p_idx] < 0.07 or sum_pdf_vals[p_idx] < max_sum_pdf:
for x,y in p:
seg_binary[i,0,x,y]=0
else:
for x,y in p:
seg_binary[i,0,x,y]=1
return seg_binary
评论列表
文章目录