Matlab gradient equivalent in opencv -
i trying migrate code matlab opencv , need exact replica of gradient function. have tried cv::sobel function reason values in resulting cv::mat not same values in matlab version. need x , y gradient in separate matrices further calculations.
any workaround achieve great
sobel can compute second derivative of image pixel not want.
(f(i+1,j) + f(i-1,j) - 2f(i,j)) / 2
what want
(f(i+i,j)-f(i-1,j)) / 2
so need apply
mat kernelx = (mat_<float>(1,3)<<-0.5, 0, 0.5); mat kernely = (mat_<float>(3,1)<<-0.5, 0, 0.5); filter2d(src, fx, -1, kernelx) filter2d(src, fy, -1, kernely);
matlab treats border pixels differently inner pixels. code above wrong @ border values. 1 can use border_constant extent border value out constant number, unfortunately constant number -1 opencv , can not changed 0 (which want).
so border values, not have neat answer it. try compute first derivative hand...
Comments
Post a Comment