def main():
imgList = getImageList(input_folder='/home/jin/shenzhenyuan/head-segmentation/input/test',
output_file='/home/jin/shenzhenyuan/head-segmentation/input/testSet.txt')
for img_path in imgList:
img = cv2.imread('{}'.format(img_path))
if img_path[:img_path.rfind('.')].endswith('png'):
str = img_path[:img_path.rfind('.')] + '-seg.png'
else:
str = img_path[:img_path.rfind('.')] + '.png-seg.png'
mask = cv2.imread('{}'.format(str))
prob = mask[:,:,0:2] / 255.0
prob[:, :, 1] = 1 - prob[:, :, 0]
res, Q = denseCRF(img, prob)
a = 1-res
a = a.astype('uint8')
r_channel, g_channel, b_channel = cv2.split(img)
img_rgba = cv2.merge((r_channel, g_channel, b_channel, a*255))
cv2.imwrite('{}_crf.png'.format(img_path[:img_path.find('.')]), img_rgba)
# a = np.dstack((a,)*3)
# plt.imshow(a*img)
# cv2.imwrite('{}_crf.png'.format(img_path[:img_path.find('.')]), (a>0.1)*img)
cv2.imwrite('{}_crf_qtsu.png'.format(img_path[:img_path.find('.')]), cropHead(Q, img))
评论列表
文章目录