深度学习之图像分割结果可视化
图像分割结果一般是二值图像(黑白),为了更好的查看分割结果我们将正确分割显示为白色,背景为黑色,错误检测为红色,漏检的为绿色。
对比结果如下:
基于python的实现代码如下:
import os
import cv2
def clmap(v, k, upBound): #mul and clamp
val = v * k
if val > upBound:
return upBound
else:
return val
source_path1 =r'G:\2\...' # <----------标签源文件路径
source_path2 =r'G:\2\...' # <----------结果源文件路径
target_path = r'G:\2\...' # <----------输出目标文件路径
image_list = os.listdir(source_path1) # 获得文件名
i = 0
for file in image_list:
print(source_path1 + "\\" + file)
img_2 = cv2.imread(source_path1 + "\\" + file) # 循环读取图片
img_1 = cv2.imread(source_path2 + "\\" + file) # 循环读取图片
img_3 = cv2.imread(r'G:\2\...') # 纯黑色背景图片
dif = img_3.copy()
show_dif = dif.copy() # dif image for show only
width = img_3.shape[0] # get width
height = img_3.shape[1] # get height
for i in range(width):
for j in range(height):
diff = int(img_1[i, j][0]) - int(img_2[i, j][0])
if diff < 0:
show_dif[i, j] = [255, clmap(abs(diff), 10, 255), 255]
elif diff > 0:
show_dif[i, j] = [255, 255, clmap(abs(diff), 10, 255)]
创作不易,还请支持: