Line detection: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 248:
 
== Code example ==
The code was used to detect only the vertical lines in an image using Matlab and the result is below. The original image is the one on the top and the result is below it. As can be seen on the picture on the right, only the vertical lines were detected
[[File:Testbuilding.jpg|thumb|Original Image]]
[[File:LineImage.jpg.png|thumb|line detection]]
<syntaxhighlight lang="matlab" line="1">
clear all
clc
%this matlab program will only detect vertical lines in an image
%benzene = imread('benzene.png');
%building = imread('building.tifjpg'); %This will upload the image building
crazy=imread('crazypic.jpg');
building=rgb2gray(crazy);
tol = 5;%define a tolerance in the angle to account for noise or edge
% that may look vertical but when the angle is computed
%it may not appear to be
[~,angle] = imgradient(building);
out = (angle >= 180 - tol | angle <= -180 + tol);%this part will filter the lines
out_filter = bwareaopen(out, 50);
figure,imshow(crazy),title('Original Image');