Extract Lines from the image

53 visualizzazioni (ultimi 30 giorni)
Atik Amin
Atik Amin il 18 Set 2023
Risposto: VINAYAK LUHA il 26 Set 2023
Dear Altruists
I want to capture any of these lines from the image and get at least two coordinate values in any of these lines.
If coordinate finding can not be done is it possible to convert these lines as .fig file or getting a linear equation for any of these lines?
Need urgent help please.
Kind Regards
  2 Commenti
Rik
Rik il 19 Set 2023
This looks like a scraped version of some plot. Can you share the original? And what have you tried so far to find a solution yourself?
Atik Amin
Atik Amin il 19 Set 2023
I have tried algorithms (Hough, Radon) suggested by MATLAB.attached is the original one

Accedi per commentare.

Risposte (1)

VINAYAK LUHA
VINAYAK LUHA il 26 Set 2023
Hi Atik,
It is my understanding that you want to identify the straight lines in your image and find their end coordinates.
Here’s a possible workaround involving preprocessing your image and extracting lines based on Hough transform-
  1. Use MATLAB’s Image thresholding app and get a binary mask of green points by adjusting values in R,G,B color space.
  2. Apply morphological transformations such as dilation, erosion etc.
  3. Apply Hough line detection as per the following documentation https://in.mathworks.com/help/images/ref/houghlines.html#buwgo_f-2_1
You can play around with parameters such as ‘FillGap’, ‘MinLength’ in the function ‘houghlines’ and specify number of peaks to detect in ‘houghpeaks’ function in the documentation.
Here’s the code for your reference-
I = imread("imgAfterColorThreshAsPerStep1.png");
SE = strel("disk",1)
I = imdilate(I,SE);
BW = edge(I,'canny');
imshow(BW);
[H,T,R] = hough(BW);
P = houghpeaks(H,13,'threshold',ceil(0.08*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
lines = houghlines(BW,T,R,P,'FillGap',1500,'MinLength',1);
figure, imshow(I),
hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end
Result
Finally you can find the final points using lines(i).point1, lines(i).point2, where i is an iterating variable.
Hope this helps.
Regards
Vinayak Luha

Community Treasure Hunt

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

Start Hunting!

Translated by