detect horizontal and vertical lines

조회 수: 14 (최근 30일)
Mohammad
Mohammad 2014년 9월 28일
댓글: Firdausy angga Permana 2017년 6월 5일
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)

채택된 답변

Image Analyst
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
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
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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by