detect horizontal and vertical lines
29 views (last 30 days)
Show older comments
Mohammad
on 28 Sep 2014
Commented: Firdausy angga Permana
on 5 Jun 2017
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 Comments
Accepted Answer
Image Analyst
on 28 Sep 2014
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 Comments
Tina
on 22 Sep 2015
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
on 5 Jun 2017
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!
More Answers (0)
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!