vision artificial parte2

Upload: pether-quezada

Post on 02-Jun-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Vision Artificial Parte2

    1/123

    Visin Artificial

    Dr. Fernando Merchn

    Facultad de Ingeniera Elctrica

    Universidad Tecnolgica de Panam

    2010

  • 8/11/2019 Vision Artificial Parte2

    2/123

    Filtros en el Dominio de la Frecuencia

  • 8/11/2019 Vision Artificial Parte2

    3/123

    Transformada de Fourier

  • 8/11/2019 Vision Artificial Parte2

    4/123

    Ejemplo 1

    ANLISIS ESPECTRALEste ejemplo muestra el uso de la funcin FFT para el anlisis espectral, para encontrar los componentes

    de la frecuencia de una seal enterrada en una seal ruidosa con dominio de tiempo.Se va ha crear datos, muestreados en 1000 Hz

    t = 0:.001:.25; Se forma un eje de tiempo desde t=0 hasta t=25 con pasosde 1 milisegundo.

    x = sin(2*pi*50*t) + sin(2*pi*120*t); Formamos una seal x, con ondas seno a 50 Hz y 120 Hz

    y = x + 0.02*rand(size(t));subplot(3,1,1), plot(t, y)title (Seal con ruidosa')

    Adicionamos ruido aleatorio con STD = 2Se genera la seal con ruido y, es dficil identificar loscomponentes de la frecuencia mirando esta seal

    Y = fft(y,256); Se aplica la transformada discreta de Fourier de la sealruidosa usando la FFT.

    Pyy = Y.*conj(Y)/256; Calcular la densidad espectral de la energa, una medida dela energa a varias frecuencias, usando la compleja

    conjugada (CONJ).f = 1000/256*(0:127); Formar un eje de frecuencia para los primeros 127 puntos y

    usarlo para diagramar el resultado. (Los restantes 256 puntosson asimtricos)

    subplot(3,1,2), plot(f, Pyy(1:128))title('Densidad espectral de la energa')xlabel('Frecuencia(Hz)')

    subplot(3,1,3), plot(f, Pyy(129:end))

    Presentar los resultados

  • 8/11/2019 Vision Artificial Parte2

    5/123

    Ejemplo 1

    0 0.05 0.1 0.15 0.2 0.25-5

    0

    5

    Tiempo de Dominio de la Seal Ruidosa

    0 50 100 150 200 250 300 350 400 450 5000

    50

    100

    0 50 100 150 200 250 300 350 400 450 5000

    50

    100Densidad espectral de la energa

    Frecuencia(Hz)

  • 8/11/2019 Vision Artificial Parte2

    6/123

    Ejemplo 2

    Haciendo uso de la funcin genwave generar y sumar 4

    ondas de frecuencias: 10, 25, 35 y 60, con amplitudes: 10,5, 10 y 5 respectivamente, 512 Hz de frecuencia demuestreo, fase = 0, la seal debe durar 0.25 segundos.

    Aplicar la FFT para identificar las frecuencias de muestreo.

    0 0.05 0.1 0.15 0.2 0.25

    -20

    -10

    0

    10

    20

  • 8/11/2019 Vision Artificial Parte2

    7/123

    function ejercicio03

    clcamp = 10; % amplitud

    fr1 = 10; % frecuencia 1

    fr2 = 25; % frecuencia 2

    fr3 = 35; % frecuencia 3

    fr4 = 60; % frecuencia 4

    sm = 512; % muestras en 1 segundo

    % (frecuencia de muestreo)

    tiempo= 0.25; % duracin de la onda

    % en segundosph = 0; % fase

    % eje de tiempo

    t = 0:1/sm:tiempo;

    Y1 = genwave(amp, fr1, sm, tiempo, ph);

    Y2 = genwave(amp/2, fr2, sm, tiempo, ph);

    Y3 = genwave(amp, fr3, sm, tiempo, ph);

    Y4 = genwave(amp/2, fr4, sm, tiempo, ph);

    % sumas las seales generadas

    y = Y1 + Y2 + Y3 + Y4;

    LEN = min(length(t), length(y));

    subplot(3,1,1), plot(t(1:LEN),y(1:LEN));

    axis([0 tiempo min(y) max(y)])

    % calcula la FFT

    Y = fft(y);

    % calcula la densidad espectral de/la energaPyy = Y.*conj(Y)/LEN;

    %considera la primera mitad para la frecuencia

    f = sm/LEN*(0:LEN/2-1);

    subplot(3,1,2), plot(f,

    Pyy(1:LEN/2)); title('DEE');

    xlabel('Frecuencia(Hz)')

    subplot(3,1,3), plot(f(1:LEN/4),

    Pyy(1:LEN/4)); title('DEE');

    xlabel('Frecuencia(Hz)')

    Ejemplo 2

  • 8/11/2019 Vision Artificial Parte2

    8/123

    Ejemplo 2

    0 0.05 0.1 0.15 0.2 0.25

    -20

    0

    20

    0 50 100 150 200 250 3000

    1000

    2000

    3000DEE

    Frecuencia(Hz)

    0 20 40 60 80 100 120 1400

    1000

    2000

    3000

    DEE

    Frecuencia(Hz)

  • 8/11/2019 Vision Artificial Parte2

    9/123

    Transformada de Fourier en 2D

  • 8/11/2019 Vision Artificial Parte2

    10/123

    The 2D Fourier Transform of a Digital Image

    ,,,21

    0

    1

    0

    Cuc

    R

    vriR

    u

    C

    v

    euvcrI

    1

    0

    21

    0

    1 ),(C

    c

    C

    uc

    R

    vriR

    rRC

    ecrIv,u

    LetI(r,c) be a single-band (intensity) digital image withR rows and C columns.Then,I(r,c) has Fourier representation

    where

    are theRx CFourier coefficients.

    these complexexponentials are 2Dsinusoids.

  • 8/11/2019 Vision Artificial Parte2

    11/123

    What are 2D sinusoids?

    Contd. on next page.

    ,

    sinsin22

    2 crNiucvr

    Nii

    eee Cuc

    Rvr

    . 122 tanand,,cos,sin uvuvuv

    where

    To simplify the situation assumeR= C=N. Then

    ,

    N

    Write

    .cossinsincossincos 22cossin2 1

    cricre cri

    Then by Eulers relation,

    Note: since images are indexedby row & col with r down and cto the right, , is positive in

    the counterclockwise direction.

  • 8/11/2019 Vision Artificial Parte2

    12/123

    What are 2D sinusoids? (contd.)

    cossincosRe 2cossin2 1

    cre cri

    cossinsinIm 2cossin2 1

    cre cri

    Both the real part of this,

    and the imaginary part,

    are sinusoidal gratings of unit amplitude, period and direction .

    ThenN

    2is the radian frequency, and the frequency, of the wavefront

    N

    and

    N is the wavelength in pixels in the wavefront direction.

  • 8/11/2019 Vision Artificial Parte2

    13/123

    13

    2D Sinusoids:

    orientation

    ... are plane waves with

    grayscale amplitudes, periods in

    terms of lengths, ...

    1cossin

    2cos2,

    cr

    AcrI

    A

    = phase shift

  • 8/11/2019 Vision Artificial Parte2

    14/123

    2D Sinusoids:

    ... specific orientations,and phase shifts.

  • 8/11/2019 Vision Artificial Parte2

    15/123

    Points on the Fourier Plane

    This point represents this particular sinusoidal grating

    x

    y

  • 8/11/2019 Vision Artificial Parte2

    16/123

    is a complexnumber with areal part and animaginary part.

    The Value of a Fourier Coefficient

    If you representthat number as amagnitude,A, anda phase, ,

    ..these represent the amplitudeand offset of thesinusoid withfrequency and direction .

  • 8/11/2019 Vision Artificial Parte2

    17/123

    The Value of a Fourier Coefficient

    The magnitude and phaserepresentation makesmore sense physically

    since the Fourier magni-tude, A (,), at point (,)represents the amplitudeof the sinusoid

    and the phase, (,),represents the offset of thesinusoid relative to origin.

  • 8/11/2019 Vision Artificial Parte2

    18/123

    The Fourier Coefficient at (u,v)

    So, the point (u,v) on theFourier plane

    represents a sinusoidal

    grating of frequency and orientation .

    represents the ampli-tude,A, and the phaseoffset, , of the sinusoid.

    The complex value,F(u,v),of the FT at point (u,v)

  • 8/11/2019 Vision Artificial Parte2

    19/123

    The Sinusoid from the Fourier Coeff. at (u,v)

  • 8/11/2019 Vision Artificial Parte2

    20/123

    FT of an Image (Magnitude + Phase)

    I log{|F{I}|2+1} [F{I}]

  • 8/11/2019 Vision Artificial Parte2

    21/123

    FT of an Image (Real +

    Imaginary)

    I Re[F{I}] Im[F{I}]

  • 8/11/2019 Vision Artificial Parte2

    22/123

    The Power SpectrumThe power spectrum of a signal is the square of the magnitude of its

    Fourier Transform.

    .ImRe

    ImReImRe

    22

    2

    vuvu

    vuivuvuivuvuvuvu

    ,,

    ,,,,,,,

    *

    For display,

    thelogofthe powerspectrum isoften used.

    At each location (u,v) it indicates the squared intensity of the frequency component

    with period and orientation22/1 vu

    ./tan 1 uv For display in Matlab:PS = fftshift(2*log(abs(fft2(I))+1));

  • 8/11/2019 Vision Artificial Parte2

    23/123

    The power spectrum (PS) is defined by .

    We take the base-e logarithm of the PS in order to view it. Otherwise its dynamic range could be

    too large to see everything at once. We add 1 to it first so that the minimum value of the result is

    0 rather thaninfinity, which it would be if there were any zeros in the PS. Recall that

    log(f2) = 2log(f ).

    Multiplying by 2 is not necessary if you are generating a PS for viewing, since you'll probablyhave to scale it into the range 0-255 anyway. It is much easier to see the structures in a Fourier

    plane if the origin is in the center. Therefore we usually perform an fftshift on the PS before it is

    displayed.

    >> PS = fftshift(log(abs(fft2(I))+1));

    >> M = max(PS(:));

    >> image(uint8(255*(PS/M)));

    If the PS is being calculated for later computational use -- for example the autocorrelation of a

    function is the inverse FT of the PS of the function -- it should be calculated by

    >> PS = abs(fft2(I)).^2;

    On the Computation of the Power Spectrum 2,IIPS vu

  • 8/11/2019 Vision Artificial Parte2

    24/123

    The Uncertainty Relation

    FT

    space frequency

    FT

    space frequency

    A small object in spacehas a large frequencyextent and vice-versa.

    216

    1

    vuyx

    vu

    yx

    then,frequency

    inextentitsisif

    andspaceinobjectthe

    ofextenttheisIf

  • 8/11/2019 Vision Artificial Parte2

    25/123

    The Uncertainty Relation

    Recall: a symmetricpair of impulses in thefrequency domain

    becomes a sinusoid inthe spatial domain.

    A symmetric pair of

    lines in the frequencydomain becomes asinusoidal line in thespatial domain.

    IFT

    spacefrequency

    l

    argeexte

    nt

    small extent

    sm

    allextent

    large extent

    IFT

    spacefrequency

    small extent

    sm

    allextent

    largeexten

    t

    large extent

  • 8/11/2019 Vision Artificial Parte2

    26/123

    The Fourier Transform of an Edge

    edge Power Spectrum Phase Spectrum

  • 8/11/2019 Vision Artificial Parte2

    27/123

    The Fourier Transform of a Bar

    bar Power Spectrum Phase Spectrum

  • 8/11/2019 Vision Artificial Parte2

    28/123

    Coordinate Origin of the FFT

    Center=

    (floor(R/2)+1, floor(C/2)+1)

    Even EvenOdd Odd

    Image Origin Weight Matrix OriginImage Origin Weight Matrix Origin

    After FFT shift After IFFT shiftAfter FFT shift After IFFT shift

  • 8/11/2019 Vision Artificial Parte2

    29/123

    Matlabs fftshiftand ifftshift

    J = fftshift(I):

    I (1,1) J ( R/2+1, C/2+1)

    I = ifftshift(J):

    J ( R/2+1, C/2+1) I (1,1)

    where x= floor(x) = the largest integer smaller thanx.

    from FFT2or ifftshift

    after fftshift

    origin origin

  • 8/11/2019 Vision Artificial Parte2

    30/123

  • 8/11/2019 Vision Artificial Parte2

    31/123

    Inverse FFTs of Impulses

    highest-possible-frequency horizontal sinusoid (Cis even)

    horizontal is thewavefront direction.

    fftshifted

  • 8/11/2019 Vision Artificial Parte2

    32/123

    Inverse FFTs of Impulses

    highest-possible-frequency vertical sinusoid (Ris even)

    vertical is thewavefront direction.

    fftshifted

  • 8/11/2019 Vision Artificial Parte2

    33/123

    Inverse FFTs of Impulses

    highest-possible-freq horizontal+vertical sinusoid (R&Ceven)

    a checker-boardpattern.

    fftshifted

  • 8/11/2019 Vision Artificial Parte2

    34/123

    Inverse FFTs of Impulses

    fftshifted

    lowest-possible-frequency horizontal sinusoid

    horizontal is thewavefront direction.

  • 8/11/2019 Vision Artificial Parte2

    35/123

    Inverse FFTs of Impulses

    fftshifted

    lowest-possible-frequency vertical sinusoid

    vertical is thewavefront direction.

  • 8/11/2019 Vision Artificial Parte2

    36/123

    Inverse FFTs of Impulses

    fftshifted

    lowest-possible-frequency negative diagonal sinusoid

    negative diagonal isthe wavefront direction.

    I FFT f I l

  • 8/11/2019 Vision Artificial Parte2

    37/123

    Inverse FFTs of Impulses

    fftshifted

    lowest-possible-frequency positive diagonal sinusoid

    positive diagonal isthe wavefront direction.

  • 8/11/2019 Vision Artificial Parte2

    38/123

    Frequencies and Wavelengths in the Fourier

    Plane

    +vdirection

    +udirection

    512 columns

    384rows

    frequencies: (u,v) = (4,3); wavelengths: (u, v) = (128,128)

    Note this and this.

  • 8/11/2019 Vision Artificial Parte2

    39/123

    Frequencies and Wavelengths in the Fourier

    Plane

    frequencies: (u,v) = (1,0); wavelength: u= 512

    u = # of complete cycles

    in the horizontal direction

    u= C/ u

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    40/123

    frequencies: (u,v) = (0,1); wavelength: v= 384

    Frequencies and Wavelengths in the Fourier

    Plane

    v = # of complete

    cycles in thevertical direction

    v=R/ v

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    41/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (2,0); wavelength: u= 256

    u = # of complete cycles

    in the horizontal direction

    u= C/ u

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    42/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (0,2); wavelength: v= 192

    v = # of complete

    cycles in thevertical direction

    v=R/ v

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    43/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (3,0); wavelength: u= 170

    u = # of complete cycles

    in the horizontal direction

    u= C/ u

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    44/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (0,3); wavelength: v= 128

    v = # of complete

    cycles in thevertical direction

    v=R/ v

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    45/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (3,3); wavelengths: (u, v) = (170,128)

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    46/123

    Frequencies and Wavelengths in the Fourier Plane

    frequencies: (u,v) = (4,3); wavelengths: (u, v) = (128,128)

    512 columns

    384rows

  • 8/11/2019 Vision Artificial Parte2

    47/123

    Power Spectrum of anImage

    Transformada de Fourier de una imagen (en Matlab)

  • 8/11/2019 Vision Artificial Parte2

    48/123

    Transformada de Fourier parauna imagen rectangular.

    b. F = fft2(f);

    S = abs(F);

    imshow(S, [ ])

    Para mover el origen de laTransformada al centro del

    rectngulo de frecuencia:

    c. Fc = fftshift(F);

    imshow(abs(Fc), [ ])

    Para hacer visible el rango

    dinmico:d. S2 = log(1 + abs(Fc));

    imshow(S2, [ ])

    Transformada de Fourier de una imagen (en Matlab)

  • 8/11/2019 Vision Artificial Parte2

    49/123

    Es muy dificil hacer asociaciones

    directas entre componentes de

    una imagen y su transformada.

    Amedida que uno se aleja del

    origen de la transformada, lasbajas frecuencias corresponden a

    las pequeas variaciones en la

    imagen.

    El espectro de Fourier muestra

    componentes prominentes a 45,correspondientes a los bordes de

    la imagen a 45, y una

    componente vertical, inclinada,

    correspondiente a la incrustacin.

  • 8/11/2019 Vision Artificial Parte2

    50/123

    FILTRADO EN EL DOMINIO

    DE LA FRECUENCIA

    Filtrado en el dominio de la frecuencia

  • 8/11/2019 Vision Artificial Parte2

    51/123

    Filtrado en el dominio de la frecuencia

    Los componente de alta frecuencia en una imagen

    corresponden a las transiciones bruscas en niveles de gris.

    El suavizado permite eliminar las componentes de altafrecuencia

    Filtro en el dominio de la frecuencia

    donde:

    F(u,v):transformada de Fourier de la imagen originalH(u,v):Filtro atenuador de frecuencias

    Filtrado en el dominio de la frecuencia

  • 8/11/2019 Vision Artificial Parte2

    52/123

    Filtrado en el dominio de la frecuencia

    Pasos para filtrar una imagen en el dominio de la

    frecuencia.

  • 8/11/2019 Vision Artificial Parte2

    53/123

    Filtrado en el dominio de la frecuencia.

    1. Obtener los parmetros de relleno

    con la funcin paddedsize.

    2. Obtener la transformada de Fourier:

    F = fft2(f, PQ(1), PQ(2));

    3. Generar la funcin del filtro.

    4. Multiplicar la transformada por el

    filtro: G = H.*F;

    5. Obtener la parte real de la

    transformada inversa de Fourier:

    g = real(ifft2(G));

    6. Recortar el rectngulo al tamao

    original:

    g = g(1:size(f, 1), 1:size(f, 2));

    Filtros pasabajo en el dominio de la frecuencia

  • 8/11/2019 Vision Artificial Parte2

    54/123

    Filtros Pasabajo en el dominio de la Frecuencia.

    1. Filtro ideal (ILPF).

    D(u,v) es la distancia desde un punto (u,v)

    al centro del filtro. D0 es un num. no-neg.

    2. Filtro Butterworth (BLPF). n es el orden del

    filtro. D0 establece la frec. de corte.

    3. Filtro Gausiano (GLPF). es la desviacin

    estandar.

    0

    0

    ),(0

    ),(1),(

    DvuDsi

    DvuDsivuH

    nDvuDvuH

    2

    0 ]/),([1

    1),(

    22 2/),(),( vuDevuH

    Filtros pasabajo en el dominio de la frecuencia

    Filtro pasabajo ideal

  • 8/11/2019 Vision Artificial Parte2

    55/123

    0

    0

    ),(0

    ),(1

    ),( DvuDsi

    DvuDsi

    vuH

    Filtro pasabajo ideal

    Filtro pasabajo Butterworth

  • 8/11/2019 Vision Artificial Parte2

    56/123

    nDvuDvuH

    2

    0 ]/),([1

    1),(

    Filtro pasabajo Butterworth

    Filtro pasabajo gausiano

  • 8/11/2019 Vision Artificial Parte2

    57/123

    Filtro pasabajo gausiano

    22 2/),(),( vuDevuH

    Resultado de filtrado ideal, Butterworth y Gausiano.

  • 8/11/2019 Vision Artificial Parte2

    58/123

    Resultado de filtrado ideal, Butterworth y Gausiano.

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

  • 8/11/2019 Vision Artificial Parte2

    59/123

    Filtros Pasabajo.Aplicacin de un filtro pasabajo

    Gaussiano a una imagen.

    PQ = paddedsize(size(f));

    [U, V] = dftuv(PQ(1), PQ(2));

    D0 = 0.05*PQ(2);F = fft2(f, PQ(1), PQ(2));

    H = exp(-(U.^2 + V.^2) /

    (2*D0^2)));

    g = dftfilt(f, H);

    b. figure, imshow(fftshift(H), [ ])c. figure, imshow(log(1 +

    abs(fftshift(F))), [ ])

    d. figure, imshow(g, [ ])

    dftuv calcula la matriz de frecuencias meshgrid

    D0 = (la desviacin estandar)

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

  • 8/11/2019 Vision Artificial Parte2

    60/123

    H = lpfilter(tipo, M,N,D0,n)

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

  • 8/11/2019 Vision Artificial Parte2

    61/123

    Aplicacin de un filtro pasabajo Gaussiano a una imagen

    Visin 3D de filtros

  • 8/11/2019 Vision Artificial Parte2

    62/123

    Visin 3D de filtros.

    a. H = fftshift(lpfilter(gaussian,

    500, 500, 50));

    mesh(H(1:10:500, 1:10:500))axis([0 50 0 50 0 1])

    b. colormap([0 0 0])

    axis off

    grid off

    c. View(-25, 30)

    d. View(-25, 0)

  • 8/11/2019 Vision Artificial Parte2

    63/123

    Funcin view.

    Los valores por defecto son az = -37.5 y el = 30

    Para determinar los valores corrientes: [az, el] =view;

    Para utilizar los valores por defectos: view(3)

  • 8/11/2019 Vision Artificial Parte2

    64/123

    Uso de la funcin Surf.

    a. H = fftshift(lpfilter(gaussian, 500, 500, 50));

    surf(H(1:10:500, 1:10:500))

    axis([0 50 0 50 0 1])colormap(gray)

    grid off; axis off

    b. Shading interp

    Filtros pasaalto

  • 8/11/2019 Vision Artificial Parte2

    65/123

    Filtros pasaalto

    0

    0

    ),(0

    ),(1),(

    DvuDsi

    DvuDsivuH

    nDvuDvuH

    2

    0 ]/),([1

    1),(

    22 2/),(),( vuDevuH

    Filtro PA Ideal

    Filtro PA Butterworth

    Filtro PA Gausiano

    D(u,v) es la distancia de un punto (u,v) al centro del filtro.

    Filtros pasaalto

  • 8/11/2019 Vision Artificial Parte2

    66/123

    Filtros pasa-alto.Utilizados para aumentar el contraste (agudizar) de

    una imagen.

    H = fftshift(hpfilter(ideal, 500, 500, 50));

    mesh(H(1: 10: 500, 1: 10: 500));

    axis([0 50 0 50 0 1])

    colormap([0 0 0])

    axis off; grid off

    d. Figure, imshow(H, [ ])

    ),(1),( vuHvuH lphp

    D(u,v) es la distancia de un punto (u,v) al centro del filtro.

    Filtros pasaalto

    Filtrado pasabajo y pasaalto

  • 8/11/2019 Vision Artificial Parte2

    67/123

    Filtrado pasabajo y pasaalto

    Filtro pasaalto ideal

  • 8/11/2019 Vision Artificial Parte2

    68/123

    Filtro pasaalto ideal

    Filtro pasaalto Butterworth

  • 8/11/2019 Vision Artificial Parte2

    69/123

    o pasaa o u e o

    Filtro pasaalto Gausiano

  • 8/11/2019 Vision Artificial Parte2

    70/123

    p

  • 8/11/2019 Vision Artificial Parte2

    71/123

    Filtro Gaussiano Pasa-alto.

    b. PQ = paddedsize(size(f));

    D0 = 0.05*PQ(1);

    H = hpfilter(gaussian, PQ(1), PQ(2), D0);

    g = dftfilt(f, H);

    figure, imshow(g, [ ])

    Se observa un aumento en la intensidad de

    bordes y transiciones

    Filtro de alta frecuencia de Enfasis.

  • 8/11/2019 Vision Artificial Parte2

    72/123

    Filtro de alta frecuencia de

    Enfasis.

    PQ = paddedsize(size(f));

    D0 = 0.05*PQ(1);

    HBW = hpfilter(btw, PQ(1),

    PQ(2), D0, 2);

    H = 0.5 + 2*HBW;

    gbw = dftfilt(f, HBW);gbw = gscale(gbw);

    ghf = dftfilt(f, H);

    ghf = gscale(ghf);

    ghe = histeq(ghf, 256);

    ),(),( vubHavuH hphfe

    El filtro pasa-alto atenua los trminos dc (constantes) de

    la imagen, como los fondos. Un desplazamiento y una

    amplificacin mejoran los resultados.

    Filtro de alta frecuencia de Enfasis.

  • 8/11/2019 Vision Artificial Parte2

    73/123

    Tcnicas de Restauracin de imagen

  • 8/11/2019 Vision Artificial Parte2

    74/123

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    75/123

    Tipos de Ruido

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    76/123

    Histogramas de modelos de ruido.

    a. r = imnoise2(gaussian, 100000, 1, 0, 1);

    %genera el vector columna r, con 100000

    elementos, siendo cada uno un nmeroaleatorio de la distribucin gaussiana, con

    mediana 0 y desviacin estndar 1. El

    histograma se obtiene con

    p = hist(r, 50)

    Tipos de Ruido

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    77/123

    Tipos de Ruido

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    78/123

    Tipos de Ruido

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    79/123

    Tipos de Ruido

    Tipos de Ruido

  • 8/11/2019 Vision Artificial Parte2

    80/123

    Tipos de Ruido

    Ruido Peridico

  • 8/11/2019 Vision Artificial Parte2

    81/123

    Ruido Peridico

    Ruido Peridico

  • 8/11/2019 Vision Artificial Parte2

    82/123

    Generacin de ruido peridico.

    uo y vo son las frecuencias con respecto

    a x y.Bx y By son desplazamientos de fase con

    respecto al origen.

    La transformada de Fourier de esta

    funcin es:

    con un par de impulsos complejos

    conjugados localizados en: (u+uo, v+vo)

    y (u-u0, v-vo).

    ]/)(2/)(2[),( 00 NByvMBxusenAyxr yx

    )],()(),()[(2

    ),(00

    /2

    00

    /2 00 vvuuevvuueA

    jvuR NBvjMBuj yx

    Ruido Peridico

  • 8/11/2019 Vision Artificial Parte2

    83/123

    Parmetros del Ruido.

    Se determina analizando el

    espectro de Fourier. Un ruido

    peridico produce picos defrecuencia.

    Para esto se utiliza el histograma,

    donde se puede obtener la media

    y la varianza utilizando momentos

    estadsticos. La forma del

    histograma est dado por sumomento central o momento

    alrededor de la media:

    1

    0

    )()(L

    i

    i

    n

    in zpmzn es el orden del momento , m es la media y 2 es la varianza.

    1

    0

    )(L

    i

    ii zpzm

    1

    0

    2

    2 )()(L

    i

    ii zpmz 0

    1

    1

    0

  • 8/11/2019 Vision Artificial Parte2

    84/123

    Filtros espaciales implementados en la funcin spfilt(g, type, m, n, parameter).

    Restauracin en presencia de ruido

  • 8/11/2019 Vision Artificial Parte2

    85/123

    Restauracin en presencia de ruido.

    a. [M, N] = size(f);

    R = imnoise2(salt & pepper, M, N, 0.1, 0);

    c = find(R==0);

    gp = f;

    gp(c) = 0;

    b. R = imnoise2(salt & pepper, M, N, 0,0.1);

    c = find(R==1);

    gs = f;

    gs(c) = 255;

    c. fp = spfilt(gp, chmean, 3, 3, 1.5);

    d. fs = spfilt(gs, chmean, 3, 3, -1.5);

    e. fpmax = spfilt(gp, max, 3, 3);

    f. fsmin = spfilt(gs, min, 3, 3);

    ),(),(),( yxyxfyxg

  • 8/11/2019 Vision Artificial Parte2

    86/123

  • 8/11/2019 Vision Artificial Parte2

    87/123

    Noise-Free Image and Uncorrelated NoiseField

  • 8/11/2019 Vision Artificial Parte2

    88/123

    Gaussian noise fieldimage

    Field

    Spectra of Noise-Free Image and Uncorr. Noise Field

  • 8/11/2019 Vision Artificial Parte2

    89/123

    noise field center row log power spectrumimage center row log power spectrum

    IID noisespectrumis flat.

    Imagespectrumfalls off.

    Sum of Noise-Free Image and Uncorrelated Noise Field

  • 8/11/2019 Vision Artificial Parte2

    90/123

    image + noise field image + noise field center row log PS

    Noise energyexceeds imageenergy beyonda certain freq.

    22 ,, uvuv 22 ,, uvuv 22 ,, uvuv

    Power Spectra of Noise-Free Image and NoiseField

  • 8/11/2019 Vision Artificial Parte2

    91/123

    Field

    noise imageoriginal image

  • 8/11/2019 Vision Artificial Parte2

    92/123

  • 8/11/2019 Vision Artificial Parte2

    93/123

    blue indicates noise > imageoriginal image

    Power Spectra of Sum of Image and Noise Field

  • 8/11/2019 Vision Artificial Parte2

    94/123

    red indicates image > noisenoise image

    Power Spectra of Sum of Image and Noise Field

  • 8/11/2019 Vision Artificial Parte2

    95/123

    image & noisenoisy image

    Power Spectra of Sum of Image and Noise Field

    Additive Noise: Another Example

  • 8/11/2019 Vision Artificial Parte2

    96/123

    original image noise image image+noise

    Additive Noise: Another Example

  • 8/11/2019 Vision Artificial Parte2

    97/123

    image PS noise PS image+noise PS

    displayed:

    1Ilog 2F

    Additive Noise: Another Example

  • 8/11/2019 Vision Artificial Parte2

    98/123

    image PS image PS > noise PSimage+noise PS

    displayed:

    1Ilog 2F

  • 8/11/2019 Vision Artificial Parte2

    99/123

    red indicates image > noise image PS > noise PS

    Additive Noise: Reduce Through

    Blurring?

    f0f0

    At some frequency,f

    0, there are more

    components wherethe noise power isgreater than theimage power.

  • 8/11/2019 Vision Artificial Parte2

    100/123

    pass

    reject

    pass

    reject

    red indicates image > noise image PS > noise PS

    Additive Noise: Reduce Through

    Blurring?

    Thus, it makessense to apply a LPFwith cutoff f0, (ablurring filter) tothe images and seewhat happens.

  • 8/11/2019 Vision Artificial Parte2

    101/123

    PS of Gaussian blurred image Gaussian Blurred Image

    Additive Noise: Reduction Through Blurring.

    The resultis actually

    no better.Theres lessnoise butthe blurringlooks worse.

  • 8/11/2019 Vision Artificial Parte2

    102/123

    PS of Gaussian blurred image Gaussian Blurred Image

    Additive Noise: Reduction Through Blurring.

    The resultis actually

    no better.Theres lessnoise butthe blurringlooks worse.

  • 8/11/2019 Vision Artificial Parte2

    103/123

    103

    red: image > noise

    blue: image < noisepower spec. of noisy image

    Noise Masking

    If the freq. comps.

    for which noise-power > image-power are known1

    1

    of course they almost never are.

  • 8/11/2019 Vision Artificial Parte2

    104/123

    Noise Masking

    mask those out

    of the FT andinvert the resultto get

    image < noise masked outpower spec. of noisy image

  • 8/11/2019 Vision Artificial Parte2

    105/123

    noisy image noise-masked mage

    Noise Masking

    this:

  • 8/11/2019 Vision Artificial Parte2

    106/123

    blurred noisy image noise-masked mage

    Noise MaskingAlthough the noise-masked image looks better than the blurred one, it is still

    noisy. Moreover, this example is unrealistic because we know the exact noise

    power spectrum. In any real case we will at most know its statistics.

    Filtrado de ruido peridico

  • 8/11/2019 Vision Artificial Parte2

    107/123

    Filtrado de ruido peridico

  • 8/11/2019 Vision Artificial Parte2

    108/123

    Ejemplo

  • 8/11/2019 Vision Artificial Parte2

    109/123

  • 8/11/2019 Vision Artificial Parte2

    110/123

  • 8/11/2019 Vision Artificial Parte2

    111/123

    Image Degradation Model

    .,N,H,I,J crcrcrcr

    undegraded

    image

    additive

    noise

    degradedimage

    pointspreadfunction

    So far, we have considered

    only additive noise. Before

    going further it will be

    useful to consider a moregeneral model of image

    degradation, one that

    includes convolution with a

    pointspread1function, H, as

    well as additive noise.

    1H is also referred to as the optical transfer function.

  • 8/11/2019 Vision Artificial Parte2

    112/123

    Pointspread OperatorsA pointspread operator is a linear model of the distortion acquired during the

    imaging process. Since it is a linear model, it is a convolution operator. One

    example of this is aperture distortion, an unavoidable consequence of making

    an image with a camera that has an opening larger than a point.

  • 8/11/2019 Vision Artificial Parte2

    113/123

    Pointspread Operators

    pinhole camera aperture camera

    A pinhole camera maps one

    object point to one image

    point; it is one-to-one.

    An aperture camera maps one

    object point to many image

    points; it spreads the points.

    P i t d O t d

  • 8/11/2019 Vision Artificial Parte2

    114/123

    Pointspread Operators and

    Convolution J , I , H ,r c r c r c

    H ,r c

    I ,r c

    Recall how a convolution works through multiply, shift, and add . That is precisely the

    effect of imaging through an aperture. It results in a blurry image.

  • 8/11/2019 Vision Artificial Parte2

    115/123

    LensesA properly designed lens will focus the light emanating from a point and thereby

    reduce the blurring. But no lens can do this perfectly. In fact, the lens adds its

    own distortion. The result is an optical transfer function, H(r,c), that is

    convolved with the image.

  • 8/11/2019 Vision Artificial Parte2

    116/123

    Image Degradation Model

    .,N,H,I,J crcrcrcr

    undegraded

    image

    additive

    noise

    degradedimage

    pointspreadfunction

    Note: The termpointspread operatorrefers to convolution by the pointspread function.

  • 8/11/2019 Vision Artificial Parte2

    117/123

    Image Degradation Model

    cr,I

    cr,J

    cr,N

    crcr ,H,I

    cr,H J , I , H , N ,r c r c r c r c

    I D d ti M d l (F

  • 8/11/2019 Vision Artificial Parte2

    118/123

    Image Degradation Model (FrequencyDomain)

    uv,

    uv,

    uv,

    uvuv ,,

    uv,Images shown are log magnitude.

    .,,,, uvuvuvuv

  • 8/11/2019 Vision Artificial Parte2

    119/123

    Modelado de la Funcin de

    Degradacin PSF.

    a. f = checkerboard(8);

    b. PSF = fspecial(motion, 7, 45);%7 pixeles a 45 grados.

    gb = imfilter(f, PSF, circular);

    c. noise = imnoise(zeros(size(f)),

    gaussian, 0, 0.001);

    d. g = gb + noise;

    imshow(pixeldup(f, 8), [ ])

    Estimacin de la funcin de degradacin

  • 8/11/2019 Vision Artificial Parte2

    120/123

    Filtro Wiener

  • 8/11/2019 Vision Artificial Parte2

    121/123

    Se utiliza cuando se tiene un amplio

    conocimiento de las propiedades de la seal

    de ruido.

    H(u,v) es la func. de degradac.

    G(u,v) es la transf. de Fourier de la imagendegradada.

    Sn(u,v) es el espectro de potencia del ruido.

    Sf(u,v) es el espectro de potencia de la

    imagen sin degradar.

    H*(u,v) es el complejo conjugado de H(u,v)

    ),(),(/),(),(),(

    ),(),(

    2

    2^

    vuGvuSvuSvuHvuH

    vuHvuF

    f

    ),(),(*),( 2

    vuHvuHvuH

    Fr = deconvwnr(g, PSF)

    % La relacin ruido a seal es 0.

    Fr = deconvwnr(g, PSF, NSPR)

    % La relacin ruido a seal es conocida.

    Fr = deconvwnr(g, PSF, NACORR, FACORR)

    % Las func. de autocorrelacin de ruido yde seal son conocidas.

    22),(),(,),(),( vuFvuSvuNvuS f

    Filtro Wiener

  • 8/11/2019 Vision Artificial Parte2

    122/123

    b. fr1 = deconvwnr(g, PSF);

    Sn = abs(fft2(noise)).^2;

    nA =

    sum(Sn(:))/prod(size(noise));Sf = abs(fft2(f)).^2;

    fA = sum(Sf(:))/prod(size(f));

    R = nA/fA;

    c. fr2 = deconvwnr(g, PSF, R);

    NCORR = fftshift(real(ifft2(Sn)));

    ICORR = fftshift(real(ifft2(Sf)));

    d. fr3 = deconvwnr(g, PSF, NCORR, ICORR);

  • 8/11/2019 Vision Artificial Parte2

    123/123

    a. f = checkerboard(8);

    imshow(pixeldup(f, 8);

    PSF = fspecial(gaussian, 7, 10);SD = 0.01; %desviacin estandar.

    b. imnoise(imfilter(f, PSF), gaussian, 0,

    SD^2); %desv. del umbral de la imag

    DAMPAR = 10*SD; %resultante.

    LIM = ceil(size(PSF, 1)/2);%lmite

    WEIGHT = zeros(size(g)); %calidadWEIGHT (LIM+1:end-LIM, LIM+1:end-

    LIM)=1; %borde de 4 ceros

    ),(*),(

    ),(*),(),(),( ^

    ^

    1

    ^

    yxfyxh

    yxgyxhyxfyxf

    k

    kk

    Algoritmo no lineal iterativo Lucy-Richardson.