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!