Curve detection using matlab

5 Ansichten (letzte 30 Tage)
Joseph Cybul
Joseph Cybul am 26 Okt. 2020
Kommentiert: Joseph Cybul am 27 Okt. 2020
Hello, I have the following image:
And im trying to find the line that goes trough the center of the red line, like this:
Any suggestions?

Akzeptierte Antwort

Stephan
Stephan am 26 Okt. 2020
Bearbeitet: Stephan am 26 Okt. 2020
here is an approach with only using Matlab basic functions:
% Open image file
I = imread('image.jpeg');
% Use Green channel for further opearations
I = I(:,:,2);
% Binarize Image
I(I>20) = 255;
I(I~=255) = 0;
% Preallocate vector of line middle coordinates
mid = 255*ones(size(I,1),1);
% loop through and find the mid of every single line
% and make a white dot at the middle position
for k = 1:numel(mid)
mid(k) = floor(median(find(I(k,:)==0)));
try
I(k,mid(k)) = 255;
catch
end
end
% show image
imshow(I)
The cordinates of the middle line are saved in mid and are NaN at all lines where no line exists-
Edit:
We can also do this without a for loop:
% Open image file
I = imread('image.jpeg');
% Use Green channel for further opearations
I = I(:,:,2);
% Binarize Image
I(I>20) = 255;
I(I~=255) = 0;
% remove content without line
I(255*size(I,2) == sum(I,2),:) = [];
% find black pixels
[r,c] = find(I==0);
% find mid in x-direction
Gx = findgroups(r);
mid_x = sub2ind([size(I,1), size(I,2)], (1:size(I,1))', floor(splitapply(@median,c,r)));
% mark the mid-line white
I(mid_x) = 255;
% show image
imshow(I)
  1 Kommentar
Joseph Cybul
Joseph Cybul am 27 Okt. 2020
Thanks a lot for the quick anwser it worked very well!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by