问题
I have a binary image in which I would like to detect curves and output the coordinate pixel positions of the curves. The image is a noisy one and I would like to detect the two curves that run horizontally.
I am using MATLAB to perform image analysis. It will be great if you can provide me some hints towards identifying these curves.
An example picture:
回答1:
Use a canny edge detector. But, in order to make it work well, you'll have to read about the parameters that go into it, and "fiddle" with them. I expect Canny edge detection to do pretty well on this data set.
edge(yourImageHere, 'canny')
回答2:
If the images stay like this, you can probably do a pretty easy way of just counting the bits line by line (but this works only, if they remain horizontal or vertical). This will give you some kind of a histogram along the y-coordinate, that lets you average your y-coordinate for one of the lines.
% Read the image
img = imread('To_detect_curves.png');
% Convert it to BW
img = rgb2gray(img);
% Get the size of the image for the loops
[width,height] = size(img);
bits_per_line = zeros(height,1);
% Sum over all lines (rows)
for idx=1:height
bits_per_line(idx) = sum(img(idx,:));
end
plot(1:height,bits_per_line)
As a result you will be having something like the following, where you can easily determine the Y coordinate for your lines.
This will surely not help you with more complex images, but for the image you provided it should do. If you have more information on what you want to do exactly, let us know.
来源:https://stackoverflow.com/questions/34860236/identify-curves-in-binary-image