Extract Lines from the image
古いコメントを表示
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
回答 (1 件)
VINAYAK LUHA
2023 年 9 月 26 日
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-
- Use MATLAB’s Image thresholding app and get a binary mask of green points by adjusting values in R,G,B color space.
- Apply morphological transformations such as dilation, erosion etc.
- 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
カテゴリ
ヘルプ センター および File Exchange で Image Transforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!