Shape Detection

Embed Size (px)

Citation preview

  • 8/7/2019 Shape Detection

    1/30

    00 -- 11

    2007 Texas Instruments Inc,

    Content developed in partnership with

    Tel-Aviv University

    From MATLAB and Simulink toReal Time with TI DSPs

    Detecting Shapes in Images usingthe Hough Transform

  • 8/7/2019 Shape Detection

    2/30

    SlideSlide 22 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Outline

    Detecting Straight Lines

    Detecting Straight Lanes

  • 8/7/2019 Shape Detection

    3/30

  • 8/7/2019 Shape Detection

    4/30

    SlideSlide 44 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Multiple Lines over a single point

    Each pair (m,b) defines a distinct straight line containing

    the point (x,y)

    (x,y)

    y=m1x+b1

    y=m2x+b2

    y=m3x+b3

    y=m4x+b4

  • 8/7/2019 Shape Detection

    5/30

  • 8/7/2019 Shape Detection

    6/30

    SlideSlide 66 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Dealing with digital pictures

    A line formed by M (N) pixels in the image space will be mapped to theintersection point of M (N) lines in the parameters space, where eachline corresponds to a pixel in the image space.

    The number of lines intersecting in a single point in the parameterspace represents the length of the original line in the image space.

    N lines

    M lines

    Image Plane Parameter Plane

  • 8/7/2019 Shape Detection

    7/30

    SlideSlide 77 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    The Accumulator Concept

    The (m.b) space (parameterplane) is subdivided in cells.

    Each pixel (x,y) in the originalimage vote in the (m,b) space

    for each line passing throughit.

    The votes are summed in anAccumulator

    bbmax

    m

    bmin

    mmin mmax

    b1

    m1

    N

    Correspondstoastraightline

    y=m1x+b1ofN pixelslength

  • 8/7/2019 Shape Detection

    8/30

    SlideSlide 88 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Using Polar Coordinates

    (x1,y1)

    (x2,y2)

    r

    UU

    UU

    UU

    sincos

    sincos

    sincos

    22

    11

    yxr

    yxr

    yxr

    !

    !

    !

    For each point (x,y) in theline the following equationapplies:

    In particular:

    UU sicos yxr !

  • 8/7/2019 Shape Detection

    9/30

    SlideSlide 99 20072007 Texas Instruments Inc,Texas Instruments Inc,

    The Motivation for Polar Coordinates

    rx

    rrx

    !

    ! 00 sicos

    x = r

    r

    Vertical lines cannot be mapped to the(m,b) space, since:

    Vertical lines can be described usingpolar coordinates :

    ?!

    g!

    b

    m

  • 8/7/2019 Shape Detection

    10/30

    SlideSlide 1010 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Hough Transform - The (r,) Space

    (x1,y1)

    (x2,y2)

    (x3,y3)

    r=x2cos+y2sin

    r=x1cos+y1sin

    r=x3cos+y3sin

    (x4,y4)

    r=x4cos+y4sin

    Hough Transform - Each point in the (x,y) space is mapped to asinusoid in the (r,) space.

    Sinusoids corresponding to collinear points in the (x,y) spaceintersect at a common point in the (r,) space.

  • 8/7/2019 Shape Detection

    11/30

    SlideSlide 1111 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Accumulators in the (r,) Plane

    max

    r

    min

    rmin rmax

    1

    r1

    N

    Correspondstothestraightline

    r1=xcos1+xsin1ofN pixelslength

  • 8/7/2019 Shape Detection

    12/30

    SlideSlide 1212 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    The Region of Interest (ROI)

    The ROI is the area in the original image, where lines need to bedetected. The ROI for the picture above is:

    xmaxxmin

    ymax

    ymin

    ree

    ee!

    ee

    ee

    3600

    022

    U

    max

    minmaxminmaxmax

    maxmin

    maxminrr

    yyxxryyy

    xxx

  • 8/7/2019 Shape Detection

    13/30

    SlideSlide 1313 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Longest Line Detection

    Edge

    Detection

    Hough

    TransfomDraw Line

    Input

    Image

    Output

    Image

    Binary

    Image

    LongestLine

    (rm,m)

    +FindMax.

    AccumulatorArray

    HoughAlgorithm

    Thelineisreconstructedusing

    theequation:

    rm=xcosm+ysinm(Calculatedforthe values of

    (x,y)that votedforthe

    accumulatorcell (rm, m).

  • 8/7/2019 Shape Detection

    14/30

    SlideSlide 1414 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Line Detection Model

  • 8/7/2019 Shape Detection

    15/30

    SlideSlide 1515 20072007 Texas Instruments Inc,Texas Instruments Inc,

    The Hough Algorithm

  • 8/7/2019 Shape Detection

    16/30

    SlideSlide 1616 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Line Drawing & Image Construction

  • 8/7/2019 Shape Detection

    17/30

    SlideSlide 1717 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Line Detection - Hands-On

    Simulation

    Implementation using the DSK6416

  • 8/7/2019 Shape Detection

    18/30

    SlideSlide 1818 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Simulation

    Image File

    MATLAB Display

    Line

    Detection

  • 8/7/2019 Shape Detection

    19/30

    SlideSlide 1919 20072007 Texas Instruments Inc,Texas Instruments Inc,

    DSK6416

    ImageFile

    MATLABDisplay

    Line

    Detection

    Script

    RGB

    to

    Grayscale

    RTDXRTDX

    Real Time Implementation

  • 8/7/2019 Shape Detection

    20/30

    SlideSlide 2020 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    From Line to Lane

    1. Find two longest lines in thepicture

    2. Draw Polygon

  • 8/7/2019 Shape Detection

    21/30

    SlideSlide 2121 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Lane Detection

    HoughTransfom

    DrawLane

    Input

    Image

    Output

    Image

    Binary

    Image

    +Find2 Max.

    Accumulator

    Array

    HoughAlgorithm

    EnhancedEdge

    Detection

    (r,)Correction

    DetermineROI

    Two Longest Lines

    (rm,m) / (rn,n)

    Twolinesarereconstructedusing the

    equation:

    rm=xcosm+ysinm(Calculatedforthe values of (x,y)that

    votedforthetwomaximum valuesin

    theaccumulatorcell.

    Apolygon is constructed connecting

    thoselines

  • 8/7/2019 Shape Detection

    22/30

    SlideSlide 2222 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Enhanced Edge Detection

    An histogram-basedthresholdingedgedetection methodenablestheidentificationofareaswherepixels changefromlighttodarkordarktolight, whichmightindicate

    laneedges.

    Edge

    Detection

    HistogramBased

    Threshold

    ROILogical

    ANDBinary

    Image

  • 8/7/2019 Shape Detection

    23/30

    SlideSlide 2323 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Edge Detection Only

    Edge Detection with HistogramBased Thresholding

    Why Enhanced Edge Detection?

  • 8/7/2019 Shape Detection

    24/30

    SlideSlide 2424 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    NoCorrection

    (r,)Correction

    The Need for (r,) Correction

    Misdetection ofthe

    longestlines

  • 8/7/2019 Shape Detection

    25/30

    SlideSlide 2525 20072007 Texas Instruments Inc,Texas Instruments Inc,

    (r,) Correction

    If the lane position given by the Hough Transform blockchanges abruptly with respect to its values in the previousframe, the Rho Theta Correction subsystem discards thecurrent position and keeps the previous position. Maximumallowable variation in E and F with respect to previous values

    are:

    degreesor

    pixelsrr

    previouscurrent

    previouscurrent

    10

    30

    e

    e

    UU

  • 8/7/2019 Shape Detection

    26/30

    SlideSlide 2626 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Lane Detection Model

  • 8/7/2019 Shape Detection

    27/30

    SlideSlide 2727 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Enhanced Edge Detection

  • 8/7/2019 Shape Detection

    28/30

    SlideSlide 2828 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    The Hough Algorithm

  • 8/7/2019 Shape Detection

    29/30

    SlideSlide 2929 20072007 Texas Instruments Inc,Texas Instruments Inc,

    Lane Drawing

  • 8/7/2019 Shape Detection

    30/30

    SlideSlide 3030 2007 Texas Instruments Inc,2007 Texas Instruments Inc,

    Lane Detection - Hands-On

    Simulation

    Implementation using the DM6437 DVDP