MATLAB Image Data Extraction Issue

조회 수: 2 (최근 30일)
peter huang
peter huang 2023년 12월 12일
답변: Aastha 2024년 12월 3일
Hello MATLAB users,
I have a question regarding MATLAB and would like to understand how to implement image recognition and extract data. Specifically, I am interested in recognizing "lines" within specific experimental data.
Due to my limited experience in image recognition, I have attempted to find code from others and tried to emulate it, but the results have not been satisfactory.
Taking this image as an example, I would like to know how to proceed in order to selectively extract only the "lines" from the data. Any relevant code or suggestions would be greatly appreciated.

답변 (1개)

Aastha
Aastha 2024년 12월 3일
To detect lines in an image, you can use the "hough" functions, which performs the Hough Transform operation. Here’s how to do it:
1. Read the image and convert it to grayscale as illustrated in the MATLAB code below:
img = imread('example.jpg');
grayImg = rgb2gray(img); % Convert to grayscale
2. Perform edge detection using the "edge" function and apply the Hough Transform to detect lines by identifying peaks in the Hough space, which correspond to potential lines. This can be done in MATLAB as follows:
edges = edge(grayImg, 'Canny');
[H, theta, rho] = hough(edges);
peaks = houghpeaks(H, 5, 'threshold', ceil(0.3 * max(H(:))));
3. Extract the lines using the peaks detected using the following code snippet:
lines = houghlines(edges, theta, rho, peaks, 'FillGap', 10, 'MinLength', 20);
4. Overlay the detected lines on the original image.
imshow(img);
hold on;
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
hold off;
Refer to the following documentation links for more information on:
I hope this is helpful!

Community Treasure Hunt

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

Start Hunting!

Translated by