Curve detection using matlab

조회 수: 5 (최근 30일)
Joseph Cybul
Joseph Cybul 2020년 10월 26일
댓글: Joseph Cybul 2020년 10월 27일
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?

채택된 답변

Stephan
Stephan 2020년 10월 26일
편집: Stephan 2020년 10월 26일
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
Joseph Cybul
Joseph Cybul 2020년 10월 27일
Thanks a lot for the quick anwser it worked very well!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by