分割结果和gt的比较, 并保存融合结果
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 20:03:42 2020
@author: deyiwang@qq.com
"""
import cv2
import os
import numpy as np
def iou(mask, result):
intersection = np.sum(np.logical_and(mask > 0, result > 0))
union = np.sum(np.logical_or(mask > 0, result > 0))
return np.sum(intersection)/np.sum(union)
def get_name(file_path, name):
input_name = file_path + name
mask_name = input_name[:-4] + '_mask' + ".jpg"#input_name[-4:]
print(input_name, mask_name)
img_mask = cv2.imread(input_name)
img_gen = cv2.imread(mask_name)
# print(img_mask.shape)
y,x,z = img_mask.shape
img_gen = cv2.resize(img_gen, (x, y), interpolation=cv2.INTER_LINEAR)
#-----
print(iou(img_mask, img_gen))
def two_mix(file_path, name):
input_name = file_path + name
img1 = cv2.imread(input_name)
mask_name = input_name[:-4] + '_mask' + ".jpg"#input_name[-4:]
print(input_name, mask_name)
img_mask = cv2.imread(input_name)
img_gen = cv2.imread(mask_name)
# print(img_mask.shape)
y,x,z = img_mask.shape
img_gen = cv2.resize(img_gen, (x, y), interpolation=cv2.INTER_LINEAR)
dst = cv2.addWeighted(img_gen, 0.5, img1, 0.5, 0)
# cv2.imshow("mixed",dst)
return dst
if __name__=="__main__":
file_path = './SegmentationClassPNG/'
inputfile = '0004.png'
# get_name(file_path, inputfile)
cv2.imshow("mixed",two_mix(file_path, inputfile))
new_name = inputfile[:-4] + '_mix' + inputfile[-4:]
cv2.imwrite(new_name, two_mix(file_path, inputfile))