DIP_Lect1

Embed Size (px)

Citation preview

  • 7/30/2019 DIP_Lect1

    1/57

    g a

    mage

    rocess ng

    ComputerGraphicsandAnimation

    RefBook:

    Digital

    Image

    Processing

    Rafael

    C.Gonzalez

    DigitalImageProcessingUsingMatlab

    Gonzalez

    20%classParticipation:Quiz&Assg

    30%MidTerm

    50%

    FinalExam

  • 7/30/2019 DIP_Lect1

    2/57

    Howan

    Image

    is

    formed

    E ectromagneticwaveSpectrum

    DIPApplication

    Imagerepresentation

    23/10/2010 2Dr N.H.Qazi IQRA University

  • 7/30/2019 DIP_Lect1

    3/57

    WhyProcessing

    mprovemento t ep ctor a n ormat on orhumanperception

    g g u u application

    23/10/2010 Dr.N.H.Qazi Iqra University 3

  • 7/30/2019 DIP_Lect1

    4/57

    DIPhasacloserelationshiptoothersciencebaseddisciplinesintermsof

    its

    technical

    content:

    Electricalengineering

    ComputerScience

    ComputerVision

    ArtificialIntelligence

    ArtificialIntelligencehasbeenimplementedusingbothelectricalandmechanicalengineeringmeans.

    u uresc ence

    may

    a ow

    eimplementationofArtificial

    Intelligencetheoryusingbiology.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 4

  • 7/30/2019 DIP_Lect1

    5/57

    PrincipleElementsofDIP

    theextension

    of

    digital

    dimensions

    possiblealso3Dimage

    dimensionoftime,t.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 5

  • 7/30/2019 DIP_Lect1

    6/57

    Ste s

    in

    Di ital

    Ima e

    rocessin

    ThebasicframeworkofaprojectinvolvingDigitalImageProcessingtoinvolvethefollowingpipeline:

    23/10/2010 Dr.N.H.Qazi IqraUniversity 6

  • 7/30/2019 DIP_Lect1

    7/57

    Example:Howtoidentifypostcodefrom

    Imageacquisition Firstweneedto roduceadi italima efroma a er

    envelope.

    This

    can

    be

    done

    using

    either

    a

    CCD

    camera,

    or

    a

    scanner Basictaskstomaketheimagesuitableforprocessing.e.g

    enhancecontrast,

    removing

    noise,

    Identifying

    region

    of

    interests.

    Segmentation:

    ,

    weextractfromtheIarge thatpartofitwhichcontainsjustthepostcode.

    .

    23/10/2010 Dr.N.H.Qazi IqraUniversity 7

  • 7/30/2019 DIP_Lect1

    8/57

    Example:Howtoidentifypostcode

    fromenvelop

    using

    DIP

    Extracting the particular features to differentiatebetween objects. Here we will be looking for curves,

    holes and corners which allow us to distinguish the

    different digits which constitute a postcode.

    .

    Assigning labels to objects based on their descriptors andassigning meanings to those labels. So we identify particular

    digits, and we interpret a string of four digits at the end of theaddress as the postcode.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 8

  • 7/30/2019 DIP_Lect1

    9/57

    Imageprocessing

    Threetypesofcomputerizedprocessingondigitalimagesaredefined: ow eve process ng,

    midlevel

    processing,

    highlevelprocesses

    LowLevelimageprocessing

    Purpose

    is

    to

    improve

    the

    visual

    qualities

    of

    image

    for

    inputtotheprocessingunitisanimageandoutputisalsoanimage

    Noisefiltering, ContentEnhancement

    23/10/2010 Dr.N.H.Qazi IqraUniversity 9

  • 7/30/2019 DIP_Lect1

    10/57

    Image enhancement

    Sharpeningordeblurring

    anoutoffocusimage,

    ,orbrighteninganimage,

    Noisefiltering, Highlightingedges

    on en

    n ancemen

    23/10/2010 Dr.N.H.Qazi IqraUniversity 10

  • 7/30/2019 DIP_Lect1

    11/57

    Imageenhancement

    23/10/2010 Dr.N.H.Qazi IqraUniversity 11

  • 7/30/2019 DIP_Lect1

    12/57

    Military

    application

    Military:useofimagingfordetectionofenemyassets,screeningofvessels,Airtoground

    IRimaging.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 12

  • 7/30/2019 DIP_Lect1

    13/57

    Medical

    application MedicalDiagnosis:Analysis

    ,

    MRIand

    CT

    images

    of

    the

    human(oranimal)bodyto

    aidinmedicaldiagnosis

    andtreatment.(looking

    inside

    23/10/2010 Dr.N.H.Qazi IqraUniversity 13

  • 7/30/2019 DIP_Lect1

    14/57

    Machinevisionapplication

    inspectionofmanufacturedpartsonproductionlines.

    AutomatedTargetdetectionandtracking

    fin er rintreco nition Machineprocessingofaerialand

    satelliteimageryforweatherrediction and cro assessment.

    Boundarydetection Iftheboundary contourareidentified

    identified.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 14

  • 7/30/2019 DIP_Lect1

    15/57

    Automatedinspection

    23/10/2010 Dr.N.H.Qazi IqraUniversity 15

  • 7/30/2019 DIP_Lect1

    16/57

    Automatedinspection

    23/10/2010 Dr.N.H.Qazi IqraUniversity 16

  • 7/30/2019 DIP_Lect1

    17/57

    Automatedinspection

    broken

    and

    missingwire.

    surface

    characterstatis is

    it

    un ormorno .isnotuniform

    differenttexture.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 17

  • 7/30/2019 DIP_Lect1

    18/57

    VideosequencingProcessing

    Majoremphasisofimagesequenceprocessingisdetectionofmovin arts

    Detectionand

    tracking

    of

    moving

    targets

    for

    Tofindoutthetrajectoryofamovingtarget

    on tor ngt emovemento organboundariesinmedicalapplication

    23/10/2010 Dr.N.H.Qazi IQRA University 18

  • 7/30/2019 DIP_Lect1

    19/57

    (EM)spectrum.

    approximately400and700nanometers.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 19

  • 7/30/2019 DIP_Lect1

    20/57

    ImageProcessing,Capture&Sampling

    Imageprocessingisbyitsverynatureaverycomputationally

    demanding

    task. IntelMMXtechnolo ies

    multiprocessorsystems (e.g.Intel

    programmablehardwaresuchas

    23/10/2010 Dr.N.H.Qazi IqraUniversity 20

  • 7/30/2019 DIP_Lect1

    21/57

    Thescene

    reflects

    radiation

    towards

    the

    camera.

    .

    Whatcould

    be

    possible

    sourceofillumination

    Electromagnetic

    spectrum

    23/10/2010 Dr.N.H.Qazi IqraUniversity 21

  • 7/30/2019 DIP_Lect1

    22/57

    Imagecapturinganddisplaying

    Captureimagefromcameraisconvertedinto

    g ta ze

    ormus ng

    converter

    an

    convertedbacktoanaloguebeforedisplaying

    23/10/2010 Dr.N.H.Qazi IqraUniversity 22

    .

  • 7/30/2019 DIP_Lect1

    23/57

    Whatisanimage

    Amultidimensionalsignal,commonly

    Howto

    store

    an

    image

    in

    acomputer

    f(x,y)=r(x,y)*i(x,y)

    Therecould

    be

    infinite

    oint

    and

    infinite

    valueoftheintensitywhattodo

    SolutionisImageDigitalization:

    samplingof

    image

    space

    and

    quantization

    of

    intensity

    23/10/2010 Dr.N.H.Qazi IqraUniversity 23

  • 7/30/2019 DIP_Lect1

    24/57

    ImageDigitalization

    Imagedigitizationistheprocessofconvertingananalogueimage,arrivingatacameralensandbeing

    projectedontheimageplane,intoan2Darrayor

    matrixofnumbers. Involvestwolevelsof:

    1.SamplingorSpatialQuantization

    . o oror n ens y grey eve uan za onorLuminanceQuantization

    23/10/2010 Dr.N.H.Qazi IqraUniversity 24

  • 7/30/2019 DIP_Lect1

    25/57

    ImageDigitalization

    Spatialquantization

    corresponds

    to

    sampling

    the

    bri htnessoftheima eatanumberof ointsusuall a

    CxR rectangulargrid.

    ThisX*Y

    dimensions

    of

    the

    image

    defined

    the

    number

    of

    pixelsusedtocoverthevisualspacecapturebythe

    image.e.g.640x480,800x600,1024x768etc.

    spatialresolution

    23/10/2010 Dr.N.H.Qazi IqraUniversity 25

  • 7/30/2019 DIP_Lect1

    26/57

    Intensit

    Quantization

    23/10/2010 Dr.N.H.Qazi IqraUniversity 26

  • 7/30/2019 DIP_Lect1

    27/57

    ImageDigitalization Intensity

    Quantization

    Avoltagevalueisobservedforeachpixelcapturedat.

    Thisvoltage

    value

    relates

    to

    the

    amount

    and

    wavelengthoflightbeingprojectedthroughthecameralenstothatpointontheimageplane(rearplaneofcamera).

    ofbinrepresentingtheintensityofcolor.

    Grayscale(8bit)commonlyhas256differentgrey

    eve s

    rang ng

    rom

    ac

    o

    w e

    Binaryimage(2bit):binaryimagehas2colour (blackorwhite

    23/10/2010 Dr.N.H.Qazi IqraUniversity 27

  • 7/30/2019 DIP_Lect1

    28/57

    ImageDigitalization

    TemporalResolution

    thisis

    the

    number

    of

    images

    captured

    in

    agiven

    timeperiod.

    Commonlyquotedasframespersecond(fps)

    eachimage

    is

    referred

    to

    as

    avideo

    frame

    (e.g.UKTVoperatesat25fps,2530fpsissuitableformostvisualsurveillance,higher

    science/engineeringcapture.

    23/10/2010 Dr.N.H.Qazi IqraUniversity 28

  • 7/30/2019 DIP_Lect1

    29/57

    Imagerepresentation

    Adigitalimagef(x,y)isdiscreteredbothinspatialcoordinatedandintensity.

    aDigitalimageisamatrixwhoserowandcolumn

    indices

    specify

    apoint

    in

    the

    image

    andelement ixel valuere resentthe ra valueorintensityvalueatthatpoint

    everypointintheimagespacehas

    Imagesizeisrepresented256X256,512x512,1024X1024

    Quantization

    :

    2

    it

    or

    B W

    ,8

    it

    or

    Gray

    image24colorimages

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 29

  • 7/30/2019 DIP_Lect1

    30/57

    Greyscale.

    Truecolour,orRGB

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 30

  • 7/30/2019 DIP_Lect1

    31/57

    T esofdi italIma e BinaryImage

    Each ixelis ustblackorwhite.

    Needsone

    bit

    per

    pixel

    suitablefortext,fingerprintsor

    architectural

    lans.

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 31

  • 7/30/2019 DIP_Lect1

    32/57

    TypesofdigitalImage GreyScale

    Each ixelisshedof re from0 black to255

    (white).

    , .

    Xrays,printedwork,natural objects

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 32

  • 7/30/2019 DIP_Lect1

    33/57

    T esofdi italIma e True

    colour,

    or

    RGB.

    .

    Eachpixelhasaparticularcolourdescribed

    by

    the

    amount

    of

    red,

    green

    and

    blue

    in

    it.

    Each ixel re uires 24 bits

    Possiblecolours2553=166777216

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 33

  • 7/30/2019 DIP_Lect1

    34/57

    TypesofdigitalImage

    Indexed.

    theima ehasanassociatedcolourma orcolour

    palette,

    which

    is

    simply

    a

    list

    of

    all

    the

    colours

    used

    inthatimage.

    Eachpixelhasavaluewhichdoesnotgiveitscolour

    (as

    for

    an

    RGB

    image),

    but

    an

    index

    to

    the

    colour

    in

    themap.

    23/10/2010 Dr.N.H.Qazi Iqra University 34

  • 7/30/2019 DIP_Lect1

    35/57

    C*R*bwhere

    C=Num ero pixe inx axis

    R=Number

    of

    pixel

    in

    yaxis

    b=numberofbitsusedtorepresentapixel.

    , image

    for

    512

    by

    512

    pixel

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 35

  • 7/30/2019 DIP_Lect1

    36/57

    =

    512*512*1=26112bits=3264bytes=3.2kb=0.03MB

    512*512*8=2097152bits=262144bytes=262kb=0.26

    Mb

    RGB

    * * = = = .

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 36

  • 7/30/2019 DIP_Lect1

    37/57

    Matrix

    A= 123 345 678

    A(1,2) A(:,3)allelementinthethirdcolumn.

    MATLABusesdataclassestorepresentthe

    pixel

    of

    the

    images

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 37

  • 7/30/2019 DIP_Lect1

    38/57

  • 7/30/2019 DIP_Lect1

    39/57

    ShortProgramme Load

    rgb file,

    convert

    it

    to

    grey,write a

    new

    file.

    a=imread('creek.tif');//load,observe a

    a(100,200,2) returnsthesecondcolorvalue(green)atthepixelinrow100andcolumn200.Ifwewanta t eco orva uesatt atpo nt,

    >>a(100,200,1:3)

    Matlab allowsaconvenient

    shortcut

    for

    listing

    all

    values

    along

    aparticular

    dimension;justusingacolononitsown:

    >>a(100,200,:)

    Auseful

    function

    for

    obtaining

    RGB

    values

    is

    impixel;

    impixel(a,200,100)

    im ixelinfo

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 39

  • 7/30/2019 DIP_Lect1

    40/57

    =

    imwrite(b,'bgray','gif');//write

    C ec t egrey eve reso ution

    a=imread(bgray.gif'); figure,imshow(c,colormap(gray(64)))

    , ,

    figure,imshow(c,colormap(gray(512)))

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 40

  • 7/30/2019 DIP_Lect1

    41/57

    Convertingintobinaryimage

    =

    imageIto

    abinary

    image.

    The

    output

    image

    BWreplacesallpixelsintheinputimagewithluminancegreaterthanlevelwiththevalue1

    (white)

    and

    replaces

    all

    other

    pixels

    with

    the

    va ue0 ac .Spec y eve nt erange 0,1 .

    a=imread('D:\matlab_DIP\Winter.bmp');

    k=im2bw(a,0.3) figure,imshow(k)

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 41

  • 7/30/2019 DIP_Lect1

    42/57

    imcontrast

    AdjustContrast

    tool

    separatefigurethatisassociatedwiththe

    grayscaleimage

    in

    the

    current

    figure,

    called

    the

    targetimage

    a=imread(blue');

    b=rgb2gray(a) imcontrast(gca)

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 42

  • 7/30/2019 DIP_Lect1

    43/57

    = ' '.

    b=rgb2gray(a); = 300:500,1:60

    figure,imshow(ff)

    Howtoaccessthecoordinatesforrgb image

    = , ,

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 43

  • 7/30/2019 DIP_Lect1

    44/57

    grayimage

    observe

    value

    of

    rg b

    . . .

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 44

  • 7/30/2019 DIP_Lect1

    45/57

    Lect2:PropertiesofImageRegion:

    PixelNeighborhood

    4neighborsN4(p)

    Apixelpatcoordinates(x,y)hasfourhorizontalandvertical

    neighbours

    whose

    coordinates

    are

    given

    by

    (x+1,y),(x1,y),(x,y+1),(x,y1)

    Aboundarypixelhaslessnumberofpixel.Eachpixelsaun t stance rom x,y

    DiagonalneighborsND(p)

    (x+1,y+1),

    (x+1,

    y1),

    (x

    1,

    y+1),

    (x

    1,

    y1)

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 45

  • 7/30/2019 DIP_Lect1

    46/57

    Thesepoints,

    together

    with

    the

    4neighbors,

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 46

    C ti it

  • 7/30/2019 DIP_Lect1

    47/57

    Connectivity

    Isaimportant

    property

    used

    for

    establishing

    Definingimagecomponents/regions

    Usedingroupingofobjectwhichmeanswhetherapixelbelongstoparticularobject

    Usingthis

    connectivity

    we

    can

    determine

    the

    boundariesoftheob ect itsareaetc.

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 47

    Connectivity

  • 7/30/2019 DIP_Lect1

    48/57

    Connectivity

    wop xe s

    are

    sa

    o

    econnec e

    na

    naryimageiftheyareadjacentinsomesense

    ,

    Theirintensity

    values

    i.e gray

    values

    are

    similar

    Example:

    two

    points

    p

    and

    q

    will

    be

    connected

    if

    q

    E

    N p orpEN q an B p =B q

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 48

    Connectivityingraylevelimage

  • 7/30/2019 DIP_Lect1

    49/57

    Connectivity in gray level image

    .

    canhaveanyvaluesfrom0to255. 4adjacency. Twopixelspandqwithvaluesfrom

    Vare4adjacentifqisinthesetN4(p).

    8adjacency. Two

    pixels

    pand

    qwith

    values

    from

    Madjacency:Ismodificationof8connectivity

    connection.Twopointsaremconnectedifoneis

    neighbourofotherandatthesametimetheydo. .

    diagonalshould

    not

    have

    any

    common

    four

    neighbour.

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 49

  • 7/30/2019 DIP_Lect1

    50/57

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 50

  • 7/30/2019 DIP_Lect1

    51/57

    Path

    Letcoordinatesofpixelp:( ,y),andofpixelq:(s,t)

    Apath

    from

    pto

    qis

    asequence

    of

    distinct

    pixels

    with

    coordinates: (x0,y0),(x1,y1),......,(xn,yn) where

    (x0,y0)=( ,y)& (xn,yn)=(s,t),

    and(xi,yi)isadjacentto(xi1,yi1)1 i n

    n

    is

    the

    length

    of

    the

    path

    Regions.

    Asetofpixelsinanimagewhereallcomponentpixelsareconnecte

    Boundaryof

    aregion

    AsetofpixelsofaregionRthathaveoneofmore neighborsa areno n

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 51

  • 7/30/2019 DIP_Lect1

    52/57

    Euclideandistance between

    pand

    q:

    , , , ,

    (s,t),and

    (u,v)

    )()(),( tysxqpDe +=

    equaltosome

    ,

    containedin

    adisk

    of

    radius

    rcentered

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 52

    , .

  • 7/30/2019 DIP_Lect1

    53/57

    cityblockdistance)

    ,

    from(x,

    y)

    less

    than

    or

    equal

    to

    some

    value

    r

    , .

    =

    The

    pixels

    with

    D4=1

    are

    the

    4

    neighbors

    of

    (x,y).How?

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 53

  • 7/30/2019 DIP_Lect1

    54/57

    |)||,max(|),(8 tysxqpD =

    w atwi pixe swit D8 istance rom x,ylessthanorequaltosomevaluerform

    ThepixelswithD8=1arethe8neighborsof(x,y).how

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 54

  • 7/30/2019 DIP_Lect1

    55/57

    Inmadjacency,Dmdistancebetweentwopointsisdefinedastheshortestmpathbetween thepoints.

    uppose a wecons era acencyo p xe sva ue

    (i.e.,V={1}). Ifp1andp3are0,thelengthoftheshortestmpath(them s ance e weenpan p s .

    Ifp1is1,thenp2andpwillnolongerbemadjacentwhy

    lengthof

    the

    shortest

    m

    path

    becomes

    3

    path??? Pp1p2p4

    betweenpand

    p4

    is

    4.

    In

    this

    case,

    the

    path

    goes

    through

    thesequenceofpoints

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 55

  • 7/30/2019 DIP_Lect1

    56/57

    .

    (a)Let

    V={0,

    1}

    and

    compute

    the

    lengths

    of

    , ,

    pandq.Ifaparticularpathdoesnotexistetween

    t ese

    two

    po nts,

    explainwhy.

    (b)Repeat

    for

    V={1,

    2}.

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 56

  • 7/30/2019 DIP_Lect1

    57/57

    23/10/2010 Dr.N.H.Qazi

    Iqra

    University 57