detect horizontal and vertical lines
조회 수: 14 (최근 30일)
이전 댓글 표시
How to detect horizontal and vertical lines in a given image using imerode function? I have this code but it doesn't detect H and V lines
im=imread('src\ima.tif');
im(:,:,2:4)=[];
im=im2bw(im);
SE = strel('arbitrary',ones(10,1));
im2 = imerode(im,SE);
imwrite(im2,'src\aa.tif');
imshow(im2)

댓글 수: 0
채택된 답변
Image Analyst
2014년 9월 28일
Just call bwconncomp(), then regionprops() and check if the bounding box height is less than some number, like 1 or 2 pixels. Untested code:
binaryImage = grayImage < 128;
cc = bwconncomp(binaryImage);
measurements = regionprops(cc, 'BoundingBox');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
if thisBB(4) <= 3 % If it's shorter than 4 lines tall.
message = sprintf('Blob #%d is horizontal.', k);
sprintf('%s\n', message);
uiwait(helpdlg(message));
end
end
댓글 수: 8
Tina
2015년 9월 22일
Hi, I'm new to Matlab and Matlab Answers. I have a query. While detecting vertical lines, what if I need to detect the lines from the alphabets also? For example quoting the same input image as above, the letter H has two vertical lines, letters R, L, D has one vertical line. How do I detect them? Thanks.
Firdausy angga Permana
2017년 6월 5일
Hi Image Analyst. I've tried this code and it's really helping me to solve my problem. But, how can we remove that lines? Thanks Before!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

