Crest Detection Implementation

I'm trying to write a ridge detection algorithm, and all the sources I found seem to combine edge detection with ridge detection. Right now, I implemented the Canny edge detection algorithm, but that’s not what I want: for example, given a single line in the image, it will effectively translate it into a double line of edges (since it will record both sides of the line) - I just want so that he reads one line.

the wikipedia article on ridge detection has a ton of mathematics, but that kind of doesn't help me as a programmer (not that I'm not inclined to mathematics, but this is not my area, and I don’t understand how to translate their differential equations into code). Is there a good source to implement this? Or, for that matter, is there a good open source implementation?

Edit: here is a simple example. Let's start with a simple line:

http://img24.imageshack.us/img24/8112/linez.th.png

>

and run Canny Algorithm to get:

http://img12.imageshack.us/img12/1317/canny.th.png

(you can see that it is thicker here - if you click on the image, you will see that these are really two adjacent lines with a space between them)

In addition, I write in C ++, but that doesn't really matter. But I want to code the algorithm, and not just write SomePackage::findRidges() and do with it.

+6
math image-processing edge-detection
source share
2 answers

You might need to think about how to clear the line that you already have, and not as detecting a tiny edge. It seems that you should do something with the morphology of the image , in particular I think about skeletonization and the operation of the limit eroded points. Used appropriately, they should remove from your image any functions that are not "strings" - I believe that they are implemented in the Intel OpenCV library.

You can restore one line from your double line generated using the Canny filter using a single extension operation followed by 3 erodes (I tried this in ImageJ) - this should also remove any edges.

+5
source share

I was about to suggest clearing your lines, as Yang said, but if you don't want to do this, you can also explore some kind of hough conversion option.

http://en.wikipedia.org/wiki/Hough_transform

You should be able to get the actual equation for the line from this, so that you can make it thin or thick as you like. The only tricky part is figuring out where the line ends.

Here is the code I wrote to convert hough a few years ago, written in MATLAB. I'm not sure how well this works, but this should give you a general idea. It will find all rows (not segments) in the image

 im = imread('cube.tif'); [bin1,bin2,bin3] = canny(im); %% define constants binary = bin1; distStep = 10; % in pixels angStep = 6; % in degrees thresh = 50; %% vote maxDist = sqrt((size(binary,1))^2+(size(binary,2))^2); angLoop = 0:angStep*pi/180:pi; origin = size(binary)/2; accum = zeros(ceil(maxDist/distStep)+1,ceil(360/angStep)+1); for y=1:size(binary,2) for x=1:size(binary,1) if binary(x,y) for t = angLoop dx = x-origin(1); dy = y-origin(2); r = x*cos(t)+y*sin(t); if r < 0 r = -r; t = t + pi; end ri = round(r/distStep)+1; ti = round(t*180/pi/angStep)+1; accum(ri,ti) = accum(ri,ti)+1; end end end end imagesc(accum); %% find local maxima in accumulator accumThresh = accum - thresh; accumThresh(logical(accumThresh<0)) = 0; accumMax = imregionalmax(accumThresh); imagesc(accumMax); %% calculate radius & angle of lines dist = []; ang = []; for t=1:size(accumMax,2) for r=1:size(accumMax,1) if accumMax(r,t) ang = [ang;(t-1)*angStep/180*pi]; dist = [dist;(r-1)*distStep]; end end end scatter(ang,dist); 
+2
source share

All Articles