Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Edge detection using hough transform.

Subject: Edge detection using hough transform.

From: rahul

Date: 4 Jan, 2013 15:59:09

Message: 1 of 6

I am using hough transform to find the edges of an arrow but i am getting only 2 of the required edges.

Original image :- <http://tinypic.com/r/35d94p1/6>> It has 7 edges.

After hough transform. <http://tinypic.com/r/2vdh9o5/6>> It is showing only 2 edges.

Why???? and how to get the all the edges???

Here is my code....(Its the same code given Matlab tutorials)

I = imread('d:\test.jpg');
rot = rgb2gray(I);
rotI = imadjust(rot);
figure(3),imshow(rotI);
BW = edge(rotI,'canny');
[H,T,R] = hough(BW);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% 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

Subject: Edge detection using hough transform.

From: Spandan.Tiwari@mathworks.com

Date: 4 Jan, 2013 16:23:06

Message: 2 of 6

Have you tried lowering the threshold parameter in houghpeaks further down? So something like:

P = houghpeaks(H,5,'threshold',ceil(0.1*max(H(:))));

I haven't tried this on your image but it seems like something worth trying out.



On Friday, January 4, 2013 10:59:09 AM UTC-5, rahul wrote:
> I am using hough transform to find the edges of an arrow but i am getting only 2 of the required edges.
>
>
>
> Original image :- <http://tinypic.com/r/35d94p1/6>> It has 7 edges.
>
>
>
> After hough transform. <http://tinypic.com/r/2vdh9o5/6>> It is showing only 2 edges.
>
>
>
> Why???? and how to get the all the edges???
>
>
>
> Here is my code....(Its the same code given Matlab tutorials)
>
>
>
> I = imread('d:\test.jpg');
>
> rot = rgb2gray(I);
>
> rotI = imadjust(rot);
>
> figure(3),imshow(rotI);
>
> BW = edge(rotI,'canny');
>
> [H,T,R] = hough(BW);
>
> P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
>
> x = T(P(:,2)); y = R(P(:,1));
>
> % Find lines and plot them
>
> lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
>
> figure, imshow(rotI), hold on
>
> max_len = 0;
>
> for k = 1:length(lines)
>
> xy = [lines(k).point1; lines(k).point2];
>
> plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
>
> % 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

Subject: Edge detection using hough transform.

From: rahul

Date: 4 Jan, 2013 19:00:09

Message: 3 of 6

yes I have done so. but that doesn't give the complete edge.
 it just give small multiple lines over the one the edges.




"Spandan.Tiwari@mathworks.com" <spandantiwari@gmail.com> wrote in message <0598071a-0961-4ab9-8dc3-ee1284aa7153@googlegroups.com>...
> Have you tried lowering the threshold parameter in houghpeaks further down? So something like:
>
> P = houghpeaks(H,5,'threshold',ceil(0.1*max(H(:))));
>
> I haven't tried this on your image but it seems like something worth trying out.
>
>
>
> On Friday, January 4, 2013 10:59:09 AM UTC-5, rahul wrote:
> > I am using hough transform to find the edges of an arrow but i am getting only 2 of the required edges.
> >
> >
> >
> > Original image :- <http://tinypic.com/r/35d94p1/6>> It has 7 edges.
> >
> >
> >
> > After hough transform. <http://tinypic.com/r/2vdh9o5/6>> It is showing only 2 edges.
> >
> >
> >
> > Why???? and how to get the all the edges???
> >
> >
> >
> > Here is my code....(Its the same code given Matlab tutorials)
> >
> >
> >
> > I = imread('d:\test.jpg');
> >
> > rot = rgb2gray(I);
> >
> > rotI = imadjust(rot);
> >
> > figure(3),imshow(rotI);
> >
> > BW = edge(rotI,'canny');
> >
> > [H,T,R] = hough(BW);
> >
> > P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
> >
> > x = T(P(:,2)); y = R(P(:,1));
> >
> > % Find lines and plot them
> >
> > lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
> >
> > figure, imshow(rotI), hold on
> >
> > max_len = 0;
> >
> > for k = 1:length(lines)
> >
> > xy = [lines(k).point1; lines(k).point2];
> >
> > plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
> >
> > % 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

Subject: Edge detection using hough transform.

From: Spandan.Tiwari@mathworks.com

Date: 4 Jan, 2013 19:43:53

Message: 4 of 6

OK, so this time I tried it out. Change the same line to the following:

P = houghpeaks(H,10,'threshold',ceil(0.1*max(H(:))));

And it should work. Here's what the result should look like:
http://tinypic.com/view.php?pic=qzqbkh&s=6

The NUMPEAKS parameter in houghpeaks() should be set keeping in mind that it is possible that a line is detected in pieces instead of a single segment.

HTH.


On Friday, January 4, 2013 2:00:09 PM UTC-5, rahul wrote:
> yes I have done so. but that doesn't give the complete edge.
>
> it just give small multiple lines over the one the edges.
>
>
>
>
>
>
>
>
>
> "Spandan.Tiwari@mathworks.com"
>
> > Have you tried lowering the threshold parameter in houghpeaks further down? So something like:
>
> >
>
> > P = houghpeaks(H,5,'threshold',ceil(0.1*max(H(:))));
>
> >
>
> > I haven't tried this on your image but it seems like something worth trying out.
>
> >
>
> >
>
> >
>
> > On Friday, January 4, 2013 10:59:09 AM UTC-5, rahul wrote:
>
> > > I am using hough transform to find the edges of an arrow but i am getting only 2 of the required edges.
>
> > >
>
> > >
>
> > >
>
> > > Original image :- <http://tinypic.com/r/35d94p1/6>> It has 7 edges.
>
> > >
>
> > >
>
> > >
>
> > > After hough transform. <http://tinypic.com/r/2vdh9o5/6>> It is showing only 2 edges.
>
> > >
>
> > >
>
> > >
>
> > > Why???? and how to get the all the edges???
>
> > >
>
> > >
>
> > >
>
> > > Here is my code....(Its the same code given Matlab tutorials)
>
> > >
>
> > >
>
> > >
>
> > > I = imread('d:\test.jpg');
>
> > >
>
> > > rot = rgb2gray(I);
>
> > >
>
> > > rotI = imadjust(rot);
>
> > >
>
> > > figure(3),imshow(rotI);
>
> > >
>
> > > BW = edge(rotI,'canny');
>
> > >
>
> > > [H,T,R] = hough(BW);
>
> > >
>
> > > P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
>
> > >
>
> > > x = T(P(:,2)); y = R(P(:,1));
>
> > >
>
> > > % Find lines and plot them
>
> > >
>
> > > lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
>
> > >
>
> > > figure, imshow(rotI), hold on
>
> > >
>
> > > max_len = 0;
>
> > >
>
> > > for k = 1:length(lines)
>
> > >
>
> > > xy = [lines(k).point1; lines(k).point2];
>
> > >
>
> > > plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
>
> > >
>
> > > % 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

Subject: Edge detection using hough transform.

From: rahul

Date: 6 Jan, 2013 12:04:08

Message: 5 of 6

"Spandan.Tiwari@mathworks.com" <spandantiwari@gmail.com> wrote in message <50ebb020-1026-4875-b0c9-a62de4a26631@googlegroups.com>...
> OK, so this time I tried it out. Change the same line to the following:
>
> P = houghpeaks(H,10,'threshold',ceil(0.1*max(H(:))));
>
> And it should work. Here's what the result should look like:
> http://tinypic.com/view.php?pic=qzqbkh&s=6
>
> The NUMPEAKS parameter in houghpeaks() should be set keeping in mind that it is possible that a line is detected in pieces instead of a single segment.
>
> HTH.
>
>
> On Friday, January 4, 2013 2:00:09 PM UTC-5, rahul wrote:
> > yes I have done so. but that doesn't give the complete edge.
> >
> > it just give small multiple lines over the one the edges.
> >
> >
> >
> > I tried what you suggested but then also its not giving the correct result.
its detecting may unwanted line from the pic.
And its drawing overlapping lines in the edges.
but I want perfect egde . How can i get that??
> >
> >
> >
> >
> >
> > "Spandan.Tiwari@mathworks.com"
> >
> > > Have you tried lowering the threshold parameter in houghpeaks further down? So something like:
> >
> > >
> >
> > > P = houghpeaks(H,5,'threshold',ceil(0.1*max(H(:))));
> >
> > >
> >
> > > I haven't tried this on your image but it seems like something worth trying out.
> >
> > >
> >
> > >
> >
> > >
> >
> > > On Friday, January 4, 2013 10:59:09 AM UTC-5, rahul wrote:
> >
> > > > I am using hough transform to find the edges of an arrow but i am getting only 2 of the required edges.
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > Original image :- <http://tinypic.com/r/35d94p1/6>> It has 7 edges.
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > After hough transform. <http://tinypic.com/r/2vdh9o5/6>> It is showing only 2 edges.
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > Why???? and how to get the all the edges???
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > Here is my code....(Its the same code given Matlab tutorials)
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > I = imread('d:\test.jpg');
> >
> > > >
> >
> > > > rot = rgb2gray(I);
> >
> > > >
> >
> > > > rotI = imadjust(rot);
> >
> > > >
> >
> > > > figure(3),imshow(rotI);
> >
> > > >
> >
> > > > BW = edge(rotI,'canny');
> >
> > > >
> >
> > > > [H,T,R] = hough(BW);
> >
> > > >
> >
> > > > P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
> >
> > > >
> >
> > > > x = T(P(:,2)); y = R(P(:,1));
> >
> > > >
> >
> > > > % Find lines and plot them
> >
> > > >
> >
> > > > lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
> >
> > > >
> >
> > > > figure, imshow(rotI), hold on
> >
> > > >
> >
> > > > max_len = 0;
> >
> > > >
> >
> > > > for k = 1:length(lines)
> >
> > > >
> >
> > > > xy = [lines(k).point1; lines(k).point2];
> >
> > > >
> >
> > > > plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
> >
> > > >
> >
> > > > % 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

Subject: Edge detection using hough transform.

From: rahul

Date: 7 Jan, 2013 13:53:10

Message: 6 of 6

"rahul " <rahul.sm01@gmail.com> wrote in message <kcbp7o$pbp$1@newscl01ah.mathworks.com>...
> "Spandan.Tiwari@mathworks.com" <spandantiwari@gmail.com> wrote in message <50ebb020-1026-4875-b0c9-a62de4a26631@googlegroups.com>...
 
yes I have tried what to told.

But still showing broken multiple lines.
Is this because of noise????

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us