Detect the shape in MATLAB
古いコメントを表示
Hello, I hope you are doing well.
I have the image of 1000x1000.I have attached the image below I want to detect the number of lines in the image and pixel value of each line. How can i do it in MATLAB
as you can see in image, there is four lines, is Hough transform work on this or any image processing.
For example line is at 720, then it show pixel value 720
2 件のコメント
Jan
2022 年 3 月 15 日
Are the lines parallel to the X axis in all cases? Then there are much cheaper methods than a Hough transformation.
Med Future
2022 年 3 月 16 日
採用された回答
その他の回答 (1 件)
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/928244/image_2732.png');
bw = im2bw(img);
% 霍夫分析
[H,T,R] = hough(bw);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(bw,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
line_r = [];
figure; imshow(img, []); hold on;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','cyan');
p = [];
xy = round(xy);
for j = min(xy(:,1)) : max(xy(:,1))
p = [p img(xy(1,2), j)];
end
text(xy(1,1),xy(1,2)-15, sprintf('pixel value = %.2f', mean(p)), 'color', 'r');
end
9 件のコメント
Med Future
2022 年 3 月 16 日
Med Future
2022 年 3 月 16 日
編集済み: Med Future
2022 年 3 月 16 日
Med Future
2022 年 3 月 16 日
Image Analyst
2022 年 3 月 16 日
Attach the actual image that you read in, not a screen capture of the final output.
yanqi liu
2022 年 3 月 17 日
yes,sir,may be upload your real image,or modify parameter,such as
P = houghpeaks(H,3,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(bw,T,R,P,'FillGap',5,'MinLength',3);
Med Future
2022 年 3 月 19 日
Image Analyst
2022 年 3 月 19 日
It should. It will find hundreds of separate lines because your lines are broken up into many, many separate segments, each with their own endpoints. However extracting the y values and using unique() will get you just the line numbers that they're on even though they're all broken up.
Med Future
2022 年 3 月 19 日
Image Analyst
2022 年 3 月 19 日
Sorry - I put it in the wrong place. it was meant to be a reply to your comment to me
カテゴリ
ヘルプ センター および File Exchange で Image Transforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

