Ask Your Question

opencv distance transform

asked 2011-12-16 12:12:44 -0500

Aditya gravatar image

updated 2011-12-16 12:14:02 -0500

I am not sure if this is the right place for an OpenCV question, but I will ask nonetheless :) I want to compute distance transform on a cv::Mat object. However, for each pixel in the matrix, along with its distance to the nearest zero pixel, I want to identify the nearest zero pixel (row/col) as well. Is there any in-built OpenCV functionality to achieve this? Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2011-12-17 03:40:12 -0500

I am not sure but I think that is called the "nearest feature transform" and AFAIK it is not implemented in OpenCV.

In any case you only want to find the nearest zero feature of a few of points you can find it integrating the trajectory which start in your "working point" following the gradient of the distance transform image. On a few steps bounded by the sqrt(width*height) you will find eventually the nearest zero feature.

edit flag offensive delete link more

answered 2011-12-16 20:53:32 -0500

noonv gravatar image

cv::distanceTransform() :)

edit flag offensive delete link more


I think my question was not clear, sorry about that. Using cv::distanceTransform, I get for each pixel the distance to the nearest zero pixel. However it does not identify the nearest zero pixel the distance is from. Is there any in built functionality to do that?
Aditya gravatar image Aditya  ( 2011-12-17 02:20:30 -0500 )edit
As far as I know - no
noonv gravatar image noonv  ( 2011-12-17 02:38:06 -0500 )edit

DIST_LABEL_PIXEL ought to identify the nearest pixel.

lucasw gravatar image lucasw  ( 2016-03-01 10:09:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-12-16 12:12:44 -0500

Seen: 1,414 times

Last updated: Apr 10 '12