Você está na página 1de 13

1

Digital image
processing
assignment









Name:v.b.akilesh arigela
Reg no:11bec0086
Slot:c1
Prof:arulmozhivarman p

Assignment no:20

Aim 1:
2
To determine the lines of required length using Hough transform.
Introduction:
To manually extract the line information from an image can be very
tiring and time-consuming especially if there are many lines in the
image. An alternate method is preferable, but is not as trivial as edge
detection since one has to determine which edge point belongs to
which line, if any. The Hough-transform makes this separation
possible and is the method we have used in our program for line
detection.
Theory of Hough transform:
It transforms between the Cartesian space and a parameter space in
which a straight line (or other boundary formulation) can be defined.
Lets consider the case where we have straight lines in an image. We
first note that for every point (x,y) in that image, all the straight lines
passing through that point satisfy Equation 1 for varying values of
line slope and intercept (m ,c)
Y=mx+c ..eqn 1
y

Lines through a point in the Cartesian domain.
At this point, it is easy to see that each different line through the
point (x,y) corresponds to one of the points on the line in the (m c,c)
space.
x

3
Now, consider two pixels P1 and P2, which lie on the same line in
the(x,y ) space. For each pixel, we can represent all the possible lines
through it by a single line in the (m ,c ) space. Thus a line in the (x ,y )
space that passes through both pixels must lie on the intersection of
the two lines in the (m ,c ) space, which represent the two pixels.
This means that all pixels which lie on the same line in the (x ,y )
space are represented by lines which all pass through a single point
in the (m ,c ) space, see Figures below

Points on the same line.

The mapping of P1 and P2 from Cartesian space to the (m ,c ) space.


Algorithm:
Following the above theory the below algorithm was developed to
detect the lines in the image.
x
y
P1
P2 Line L
m
c
P1
P2
Line L
4
1.Input the image
2. Use the hough function to detect lines in an image.
The function returns H, the Hough transform matrix. theta (in
degrees) and rho are the arrays of rho and theta values over which
hough generates the Hough transform matrix.
3. Locate peaks in the Hough transform matrix H, generated by the
hough function.
4. Extract line segments in the image BW associated with particular
bins in a Hough transform (with given requirements).
5.Plot the beginning and ends of the lines.
Matlab code:
clc;
I = imread('pea1.jpg');
rotI = imrotate(I,360,'crop');
bw_I = rgb2gray(rotI);
BW = edge(bw_I,'canny');
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P =
houghpeaks(H,120,'threshold',ceil(0.3*max(H(:))
));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
% Find lines and plot them
lines =
houghlines(BW,T,R,P,'FillGap',3,'MinLength',11)
;
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
5
xy = [lines(k).point1; lines(k).point2];

plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','gre
en');
% Plot beginnings and ends of lines

plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color',
'yellow');

plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color',
'red');
end


Results:
Input image



Output image:

6











Transform bin image that represents number of peaks:

7


Conclusion:
The classical Hough transform was concerned with the identification
of lines in the image, but later the Hough transform has been
extended to identifying positions of arbitrary shapes, most
commonly circles or ellipses.








8
Aim 2:
To experiment hough circle detector.
Algorithm:
1.read the given image.
2.set minimum amd maximum radii of circles to be detected.
3. Find circles using circular Hough transform.
(function is imfindcircles)
4. draw circles with specified centers and radii on to the current
axes.
Matlab code:
clc;
A = imread('cir.jpg');
imshow(A)
Rmin = 8;
Rmax = 60;
[centersBright, radiiBright] =
imfindcircles(A,[Rmin
Rmax],'ObjectPolarity','bright');
[centersDark, radiiDark] =
imfindcircles(A,[Rmin
Rmax],'ObjectPolarity','dark');
viscircles(centersBright,radiiBright,'EdgeColor
','b');
viscircles(centersDark,
radiiDark,'LineStyle','--');







9
Results:

Input image












10

Output image:









11
Similarly when another image that dont contain perfect circles is
gives the results are as follows.
Input image










Output image:
12


Limitations:
The Hough transform is only efficient if a high number of votes
fall in the right bin, so that the bin can be easily detected amid
the background noise. This means that the bin must not be too
small, or else some votes will fall in the neighboring bins, thus
reducing the visibility of the main bin.
Use of the Hough transform on noisy images is a very delicate
matter and generally, a denoising stage must be used before.




References:
13
Mathworks.com
Wikipedia
Jensen, Jeppe. "Hough Transform for Straight Lines".
Retrieved 16 December 2011.

Você também pode gostar