Normalize kernel for Sobel filter

142 Views Asked by At

I'm trying to compute the Normal Map by taking the derivative of depth map for that I'm using Sobel filter:

d_im = cv2.imread('vin.png')
zx = cv2.Sobel(d_im, cv2.CV_64F, 1, 0, ksize=5)     
zy = cv2.Sobel(d_im, cv2.CV_64F, 0, 1, ksize=5)

normal = np.dstack((-zx, -zy, np.ones_like(d_im)))
n = np.linalg.norm(normal, axis=2)
normal[:, :, 0] /= n
normal[:, :, 1] /= n
normal[:, :, 2] /= n

As seen below the result seems to have a harsh transition in the x, y direction: enter image description here

I read somewhere as I was trying to find a solution for the issue(Unfortunately, I can't find the reference anymore) that this can be fixed by normalizing one side of the kernel. I am not sure what does that mean. is it summing one side then multiplying the kernel by 1/sum? If that does not sound right is there any method to get a better result that is less harsher than the result I'm getting ?

0

There are 0 best solutions below