Está en la página 1de 22

Universidad Nacional de Crdoba

Facultad de Ciencias Exactas Fsicas y Naturales


Procesamiento de Seales

Trabajo Prctico N1
-Tema C-

Alumno: Maestri, Franco


Docentes: Dra. Vera de Payer, Elizabeth del Valle
Ing. Armesto, Juana
Mgter. Rulloni, Valeria

Seales Bidimensionales
1. Graficar las seales discretas x1 y x2.
a) x1[n]=3n-2, 0n4
>>n=[0:1:4];
x1=3n-2;
plot(x1);

b) x2[n]=sin(n/3), 0n6
>>n=[0:1:6];
x2=sin(n*pi/3);
plot(x1);

2.
a) Dar la transforma de Fourier Discreta punto N, con N=6, de x1 y x1.
>>Fx1=fft(x1,6);
Fx1 = 0.0000

-0.0000 - 3.0000i 0.0000

-0.0000

0.0000

-0.0000 + 3.0000i

-0.0000 - 3.0000i 0.0000

-0.0000

0.0000

-0.0000 + 3.0000i

>>Fx1=fft(x2,6)
Fx1 = 0.0000

Graficar por separado la parte real e imaginaria de cada una:


>>stem(real(Fx1))
stem(imag(Fx1))
stem(real(Fx2))
stem(imag(Fx2))

M=20

M=0

c) Pensando en la extensin de la seal x1 a una seal peridica de perodo N=7, denotada x3,
calcular los coeficientes de la Serie de Fourier:
>>x3=[-2 1 4 7 10 0 0]
fft(x3)
ans =
Columns 1 through 6
20.0000
1.5849i

-17.5831 - 3.3799i 4.7729 - 1.5849i -4.1899 + 5.6182i -4.1899 - 5.6182i 4.7729 +

Column 7
-17.5831 + 3.3799i

d) Calcule la convolucin lineal entre x1 y x2.


>>conv(x1,x2)
ans = 0, -1.7321, -0.8660, 4.3301, 11.2583, 15.5885, 4.3301, -9.5263, -14.7224, -8.6603, -0.0000

e) Calcule la convolucin circular de 8 puntos de las seales x1 con x2 (denotada por x1*x2).
Tenemos que la convolucin circular entre x1 y x2 es igual a la antitransformada del producto de
sus respectivas transformadas de Fourier. Para que se cumpla que la convolucin circular coincida
con la lineal, se debe cumplir que Nn+m-2, siendo m y n los elementos de x1 y x2. Para este caso
N7+7-2=12. En matlab:
>>convcx1x1=ifft(fft(x1,12).*fft(x2,12))
convcx1x1 =
Columns 1 through 10
-0.0000 -1.7321 -0.8660 4.3301 11.2583 15.5885 4.3301 -9.5263 -14.7224 -8.6603
Columns 11 through 12
0

Que son los mismos valores obtenidos en la convolucin lineal hecha anteriormente.

3. Calcular el producto de convolucin 2-D de las imgenes representadas por las matrices A y B
>> A=[3,1,-1;0,2,1];
B=[3,2,2;1,1,2;0,2,1];
conv2(A,B);
ans =
9 9 5 0 -2
3 10 13 7 0
0 8 8 4 1
0 0 4 4 1
4. Genere y grafique una imagen con 7 bandas verticales con niveles de gris decrecientes
del blanco al negro.
>>b=ones(32);
linea=[0.*b, .2.*b, .4.*b, .6.*b, .8.*b, b];
bandas=[linea;linea;linea;linea;linea];
imshow(bandas)

5. Obtenga la DFT 2-D de la imagen del ejercicio 3 y grafique su valor absoluto, el valor
absoluto centrado y una transformacin logartmica de esta ltima.
>>c=conv2(A,B);
C=fftshift(fft(c));
subplot(1,3,1), imshow(abs(C)), title Abs;
subplot(1,3,2), imshow(abs(fftshift(c))), title Centrada;
subplot(1,3,3), imshow(0.2*log(1+abs(fftshift(c)))), title Log;
6. Forme una coleccin de las 3 imgenes graficadas en el ejercicio 5.

Mejora de Imagen
1. Dada las imgenes Degrad horizontal de gris y Damero en negro y gris, aplique la
transformada de Fourier de dichas imgenes una transformacin logartmica conveniente
para visualizarla correctamente.
>> I=checkerboard(8);
b=ones(32); linea=[0.*b, .2.*b, .4.*b, .6.*b, .8.*b, b];
bandas=[linea;linea;linea;linea;linea];
subplot(1,2,1), imshow(0.2*log(1+abs(fftshift(fft(I))))), title Damero;
subplot(1,2,2), imshow(0.2*log(1+abs(fftshift(fft(bandas))))), title Bandas;

2. Elija una imagen y haga las siguientes transformaciones:


>>G=imread(grand_i.jpg');
GG=rgb2gray(G);
imshow(GG);

a)Convirtala a su negativo:
>> GGN=imadjust(GG,[0 1],[1 0],1);
imshow(GGN)

b)Aclrela
>> GGA=imadjust(GG,[], [0.2 1],0.4);
imshow(GGA);

c) Oscurzcala
>> GGO=imadjust(GG,[],[],1.6);
imshow(GGO);

d) Realce niveles intermedios de gris


>> GGG=imadjust(GG,[.45 .55],[0.7 0.8], 1);
imshow(GGG);

Histogramas:
>> subplot(2,3,1), imhist(GG), title 'Blanco y Negro'; subplot(2,3,2), imhist(GGN), title 'Negativo';
subplot(2,3,3), imhist(GGA), title 'Aclarada'; subplot(2,3,4), imhist(GGO), title 'Oscurecida';
subplot(2,3,5), imhist(GGG), title 'Realce de niveles medios';

3. Ecualice los histogramas de los ejercicios anteriores. Muestre los resultados obtenidos
comparando con las imgenes originales.

>> GGEQ=histeq(GG); GGNEQ=histeq(GGN); GGAEQ=histeq(GGA); GGOEQ=histeq(GGO);


GGGEQ=histeq(GGG);

>>subplot(2,3,1), imhist(GGEQ), title 'Blanco y Negro';


subplot(2,3,2), imhist(GGNEQ), title 'Negativo';
subplot(2,3,3), imhist(GGAEQ), title 'Aclarada';
subplot(2,3,4), imhist(GGOEQ), title 'Oscurecida';
subplot(2,3,5), imhist(GGGEQ), title 'Realce de niveles medios';

Las imgenes, luego de la ecualizacin de histograma, resultan:


>>subplot(2,3,1), imshow(GGEQ), title 'Blanco y Negro';
subplot(2,3,2), imshow(GGNEQ), title 'Negativo';
subplot(2,3,3), imshow(GGAEQ), title 'Aclarada';
subplot(2,3,4), imshow(GGOEQ), title 'Oscurecida';
subplot(2,3,5), imshow(GGGEQ), title 'Realce de niveles medios';
subplot(2,3,6), imshow(GG), title 'Original';

4. Disee dos filtros espaciales y aplquelos a las imgenes de los ejercicios anteriores.
Muestre los resultados obtenidos.

>> F1=1/9*[1 1 1;0 0 0;-1 -1 -1];


>> subplot(2,3,1), imshow(filter2(F1,GG)), title 'Blanco y Negro';
subplot(2,3,2), imshow(filter2(F1,GGN)), title 'Negativo';
subplot(2,3,3), imshow(filter2(F1,GGA,'full')), title 'Aclarada';
subplot(2,3,4), imshow(filter2(F1,GGO,'full')), title 'Oscurecida';
subplot(2,3,5), imshow(filter2(F1,GGG,'full')), title 'Realce de niveles medios';
subplot(2,3,6), imshow(GG), title 'Original';

>>F2=(1/3000)*[1 1 1; 1 1 1;1 1 1];


>>subplot(2,3,1), imshow(filter2(F2,GG)), title 'Blanco y Negro';
subplot(2,3,2), imshow(filter2(F2,GGN)), title 'Negativo';
subplot(2,3,3), imshow(filter2(F2,GGA,'full')), title 'Aclarada';
subplot(2,3,4), imshow(filter2(F2,GGO,'full')), title 'Oscurecida';
subplot(2,3,5), imshow(filter2(F2,GGG,'full')), title 'Realce de niveles medios';
subplot(2,3,6), imshow(GG), title 'Original';

Restauracin de la Imagen

1) Dada la imagen Niveles de gris, contaminar


con dos tipos y niveles de ruido.
>>b=ones(32);
linea=[0.*b, .2.*b, .4.*b, .6.*b, .8.*b, b];
bandas=[linea;linea;linea;linea;linea];
imshow(bandas)

>>Isyp1=imnoise(bandas,'salt & pepper', 0.05);


Isyp2=imnoise(bandas,'salt & pepper', 0.1);
Ig1=imnoise(bandas,'gaussian',0.01);
Ig2=imnoise(bandas,'gaussian',0.1);
>>subplot(2,2,1),imshow(Isyp1),title 'Ruido Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2),title 'Ruido Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1),title 'Ruido Gaussiano bajo'
subplot(2,2,4),imshow(Ig2),title 'Ruido Gaussiano alto'

2) Utilice dos filtros de valor medio y el filtro de mediana.


Filtro de valor medio N1:
>>Isyp1fvm=ordfilt2(Isyp1,5,ones(3));
Isyp2fvm=ordfilt2(Isyp2,5,ones(3));
Ig1fvm=ordfilt2(Ig1,5,ones(3));
Ig2fvm=ordfilt2(Ig2,5,ones(3));
>>subplot(2,2,1),imshow(Isyp1fvm),title 'Filtro de Valor Medio, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fvm),title 'Filtro de Valor Medio, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fvm),title 'Filtro de Valor Medio, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fvm),title 'Filtro de Valor Medio, Gaussiano alto'

Filtro de Valor medio N2:


>>Isyp1fvm=ordfilt2(Isyp1,13,ones(5));
Isyp2fvm=ordfilt2(Isyp2,13,ones(5));
Ig1fvm=ordfilt2(Ig1,13,ones(5));
Ig2fvm=ordfilt2(Ig2,13,ones(5));
>>subplot(2,2,1),imshow(Isyp1fvm),title 'Filtro de Valor Medio, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fvm),title 'Filtro de Valor Medio, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fvm),title 'Filtro de Valor Medio, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fvm),title 'Filtro de Valor Medio, Gaussiano alto'

Filtro de Mediana:
>>Isyp1fmed=medfilt2(Isyp1);
Isyp2fmed=medfilt2(Isyp2);
Ig1fmed=medfilt2(Ig1);
Ig2fmed=medfilt2(Ig2);
>>subplot(2,2,1),imshow(Isyp1fmed),title 'Filtro de Mediana, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fmed),title 'Filtro de Mediana, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fmed),title 'Filtro de Mediana, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fmed),title 'Filtro de Mediana, Gaussiano alto'

3)

Para el caso de las bandas de grises, los mtodos de mejora de imagen no han presentado
ninguna diferencia notable. Para un caso diferente, segn sea el tipo de ruido, dar
mejores resultados utilizar un filtro u otro.

4) Repetir los pasos anteriores para la imagen Checkerboard.


Obtener imagen:
>>I=checkerboard(8);
imshow(I)

Aadir Ruido:
>>Isyp1=imnoise(I,'salt & pepper', 0.05);
Isyp2=imnoise(I,'salt & pepper', 0.1);
Ig1=imnoise(I,'gaussian',0.01);
Ig2=imnoise(I,'gaussian',0.1);
>>subplot(2,2,1),imshow(Isyp1),title 'Ruido Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2),title 'Ruido Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1),title 'Ruido Gaussiano bajo'
subplot(2,2,4),imshow(Ig2),title 'Ruido Gaussiano alto'

Filtro de Valor medio N1:


>>Isyp1fvm=ordfilt2(Isyp1,5,ones(3));
Isyp2fvm=ordfilt2(Isyp2,5,ones(3));
Ig1fvm=ordfilt2(Ig1,5,ones(3));
Ig2fvm=ordfilt2(Ig2,5,ones(3));
>>subplot(2,2,1),imshow(Isyp1fvm),title 'Filtro de Valor Medio, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fvm),title 'Filtro de Valor Medio, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fvm),title 'Filtro de Valor Medio, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fvm),title 'Filtro de Valor Medio, Gaussiano alto'

Filtro de Valor medio N2:


>>Isyp1fvm=ordfilt2(Isyp1,13,ones(5));
Isyp2fvm=ordfilt2(Isyp2,13,ones(5));
Ig1fvm=ordfilt2(Ig1,13,ones(5));
Ig2fvm=ordfilt2(Ig2,13,ones(5));
>>subplot(2,2,1),imshow(Isyp1fvm),title 'Filtro de Valor Medio, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fvm),title 'Filtro de Valor Medio, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fvm),title 'Filtro de Valor Medio, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fvm),title 'Filtro de Valor Medio, Gaussiano alto'

Filtro de Mediana:
>>Isyp1fmed=medfilt2(Isyp1);
Isyp2fmed=medfilt2(Isyp2);
Ig1fmed=medfilt2(Ig1);
Ig2fmed=medfilt2(Ig2);
>>subplot(2,2,1),imshow(Isyp1fmed),title 'Filtro de Mediana, Salt & Pepper bajo'
subplot(2,2,2),imshow(Isyp2fmed),title 'Filtro de Mediana, Salt & Pepper alto'
subplot(2,2,3),imshow(Ig1fmed),title 'Filtro de Mediana, Gaussiano bajo'
subplot(2,2,4),imshow(Ig2fmed),title 'Filtro de Mediana, Gaussiano alto'

Para este nuevo caso se encontr un desempeo muy similar para el primer filtro de valor
medio y el filtro de mediana, pero se encontr una gran diferencia en el segundo filtro de valor
medio utilizado. Para este ltimo la calidad obtenida no fue tan buena como las dems, ya que
este utiliza una matriz de unos ms grande para realizar el filtrado, por lo que al calcular el
promedio de los valores se observan los resultados mostrados anteriormente.

5) Durante la adquisicin de una imagen, sufre un movimiento lineal uniforme en la direccin


vertical y luego otro en direccin horizontal.
>>I=checkerboard(8);
H=fspecial('motion',5,5);
Imov=imfilter(I,H);
>>subplot(1,2,1), imshow(I), title 'Tablero';
subplot(1,2,2), imshow(Imov), title 'Imagen Movida';

6)Utilice filtrado inverso para recuperar la imagen


>>whos I
Name

Size

64x64

Bytes Class
32768 double array

Grand total is 4096 elements using 32768 bytes


>>FH=fft2(H,64,64);
FI=fft2(I,64,64);
Ifi=ifft2(FI./(FH+1));
>> imshow(Ifi), title 'Imagen Recuperada';

También podría gustarte