Curve detection using matlab
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joseph Cybul
el 26 de Oct. de 2020
Comentada: Joseph Cybul
el 27 de Oct. de 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?
0 comentarios
Respuesta aceptada
Stephan
el 26 de Oct. de 2020
Editada: Stephan
el 26 de Oct. de 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)
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!