def vis_detect(image_name, thresh=0.0):
image = cv2.imread(image_dir + image_name + '.png', 0)
json_file = label_dir + image_name + '.txt'
image_data = read_json(json_file)
fig = plt.figure(figsize=(20,40))
ax1 = fig.add_subplot(121, aspect='equal')
ax1.imshow(image,cmap='gray')
gt = 0
for ix, nodule in enumerate(image_data['nodes']):
contours = np.array(nodule['rois'][0]['edge'])
if nodule['type'].lower() == 'mass':
points = contours[:, np.newaxis, :]
x1, y1, w, h = cv2.boundingRect(points)
# print(x1, y1, w, h)
rect = patches.Rectangle(
(x1, y1), # (x,y)
w, # width
h, # height
linewidth=2,edgecolor='r',facecolor='none'
)
ax1.add_patch(rect)
gt += 1
ax2 = fig.add_subplot(122, aspect='equal')#name, shape, image_dir, label_dir
mask, label = get_label_mask(image_name, image.shape, image_dir, label_dir)
predicts, segms, scores = get_my_predicts(thresh, image_name)
for bbox, predict_segm, score in zip(predicts, segms, scores):
if if_mask_overlap(mask, predict_segm, 0.5) > 0:
print bbox, score
x1,y1,w,h = bbox
segm_mask = mask_util.decode(predict_segm)
if segm_mask.sum() > 0:
contours = find_contours(segm_mask, 0.5)
# print len(contours)
contour = contours[0]
ax2.plot(contour[:, 1], contour[:, 0], linewidth=2)
rect = patches.Rectangle(
(x1, y1), # (x,y)
w, # width
h, # height
linewidth=2,edgecolor='g',facecolor='none'
)
ax2.add_patch(rect)
ax2.imshow(image,cmap='gray')