wywu / LAB

[CVPR 2018] Look at Boundary: A Boundary-Aware Face Alignment Algorithm
https://wywu.github.io/projects/LAB/LAB.html
Other
1.01k stars 273 forks source link

the details of generate boundary map #3

Closed wuneng closed 6 years ago

wuneng commented 6 years ago

Hi,wywu Thanks for your impressive work. I am try my best to generate boundary map as same as the one in your paper.Unfortunately, there are large difference between the generate boundary map and yours. In my implement, i set the resolution 256,line width 20 in binary map and distance type L2,masksize 5 in distance map.I want to know the parameter in your setting. Thanks in advance.

wywu commented 6 years ago

Hi,

Line width is 1 pixel in our implementation. With a binary boundary map img_boundary.jpg (where pixels of the boundary line are set to be 255 while others are set to be 0), you can use the code below to get the distance transform results. Then the ground-truth boundary heatmap cen be obtained with Eq.1 in our paper.

`import cv2 import numpy as np import matplotlib.pyplot as plt

img = cv2.imread('img_boundary.jpg', 0) dist = cv2.distanceTransform(255-img, cv2.DIST_L2, cv2.DIST_MASK_PRECISE) plt.figure() plt.imshow((dist).astype(np.uint8), cmap='gray') plt.show()`

Best, Wayne

wuneng commented 6 years ago

Hi, wywu Thanks for your reply. I have modified the code.Here is my code. import cv2 import numpy as np import matplotlib.pyplot as plt from utils import loadFromPts import skimage.io as io

image = io.imread('/home/xiang/pytorch/testset/common/123.jpg') ldms = loadFromPts('/home/xiang/pytorch/testset/common/123.pts')

def gauss(x, a, b, c, d=0): return a * np.exp(-(x - b) * 2 / (2 c ** 2)) + d

def color_heatmap(x):

color = np.zeros((x.shape[0],x.shape[1],3))
color[:,:,0] = gauss(x, .5, .6, .2) + gauss(x, 1, .8, .3)
color[:,:,1] = gauss(x, 1, .5, .3)
color[:,:,2] = gauss(x, 1, .2, .3)
color[color > 1] = 1
color = (color * 255).astype(np.uint8)
return color

binary_map = np.zeros([256,256]).astype(np.uint8) for i in range(15): binary_map = cv2.line(binary_map,tuple(ldms[i].astype(np.int32)),tuple(ldms[i+1].astype(np.int32)),(255),1)

plt.imshow(binary_map)

dist = cv2.distanceTransform(255-binary_map, cv2.DIST_L2, cv2.DIST_MASK_PRECISE)

print(np.max(dist),np.min(dist))

plt.figure()

plt.imshow((dist).astype(np.uint8), cmap='gray')

plt.imshow((dist).astype(np.uint8), cmap='gray')

plt.show()

dist = dist / (np.max(dist)) heatmap = color_heatmap(dist) new_img = (image0.7 + heatmap0.3).astype(np.uint8) plt.imshow(new_img)

I still can not get the result as same as the distance map in your paper. Maybe some difference in the visualization function between yours and mine? The visualization of distance map uploaded to Baidu Drive,https://pan.baidu.com/s/13WxL6yUMIIPUlJZJI4wu2A(since some went wrong with github, i can not upload the distance map to github). Thanks.

wywu commented 6 years ago

Hi,

It could be better to discuss the detail problem by e-mail. Please contact me at wuwenyan0503@gmail.com

Best, Wayne

misnowman commented 5 years ago

想请教下是怎么生成轮廓线的,直接画多边形吗