convolucion

25
USO DE MATLAB PARA HACER UNA CONVOLUCION DE UN ARCHIVO DE IMAGEN

Upload: alex-lopez

Post on 26-Oct-2014

140 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Convolucion

USO DE MATLAB

PARA HACER UNA

CONVOLUCION

DE UN ARCHIVO

DE IMAGEN

Page 2: Convolucion

PROCEDIMIENTO:PROCEDIMIENTO:PROCEDIMIENTO:PROCEDIMIENTO:LA IMAGEN SELECCIONADA SE MUESTRA EN LA PARTE DE ABAJO, PROCEDEMOS PRIMERO A APLICAR EL CODIGO DE MATLAB CON UNA RESPUESTA A LA MUESTRA UNITARIA DE h [n] = [1/32,1/32,1/32]

Page 3: Convolucion

CON UNA RESPUESTA A LA MUESTRA:h[n] =[1/32,1/32,1/32]

>> x=>> x=>> x=>> x=imreadimreadimreadimread('C:('C:('C:('C:\\\\Dark.jpg');Dark.jpg');Dark.jpg');Dark.jpg');% almacena en forma de matriz en la variable x el archivo de imagen deseado. >> >> >> >> h =[1/32,1/32,1/32];

% respuesta al impulso deun filtro pasa bajas por el cual se convolucionará lamatriz de la imagen>> y=>> y=>> y=>> y=convnconvnconvnconvn((((x,hx,hx,hx,h););););% Comando que realiza la operación de convolución>> >> >> >> imwriteimwriteimwriteimwrite((((y,'Cy,'Cy,'Cy,'C::::\\\\Darkreponse2.jpg');Darkreponse2.jpg');Darkreponse2.jpg');Darkreponse2.jpg');% Crea el archivo de imagen, resultado de la convolucion de la original con la muestra a la respuesta unitaria.

CODIGO DE MATLABCODIGO DE MATLABCODIGO DE MATLABCODIGO DE MATLAB

Page 4: Convolucion

IMAGEN ORIGINAL

IMAGEN TRAS LA CONVOLUCION CON LA RESPUESTA (1/32)

Page 5: Convolucion

>> x=imread('C:\Dark.jpg');>> h =[1/300,1/300,1/300];>> y=convn(x,h);>> imwrite(y,'C:\Darkreponse3.jpg');

CON UNA RESPUESTA A LA MUESTRA:h[n] =[1/300,1/300,1/300]

Page 6: Convolucion

Imagen original

Imagen después del filtro (1/300)

Page 7: Convolucion

>> x=>> x=>> x=>> x=imreadimreadimreadimread('C:('C:('C:('C:\\\\Dark.jpg');Dark.jpg');Dark.jpg');Dark.jpg');% almacena en forma de matriz en la variable x el archivo de imagen deseado. >> h=[1/500,1/500,1/500];>> h=[1/500,1/500,1/500];>> h=[1/500,1/500,1/500];>> h=[1/500,1/500,1/500];% respuesta al impulso deun filtro pasa bajas por el cual se convolucionará lamatriz de la imagen>> y=>> y=>> y=>> y=convnconvnconvnconvn((((x,hx,hx,hx,h););););% Comando que realiza la operación de convolución>> >> >> >> imwriteimwriteimwriteimwrite((((y,'Cy,'Cy,'Cy,'C::::\\\\Darkreponse.jpg');Darkreponse.jpg');Darkreponse.jpg');Darkreponse.jpg');% Crea el archivo de imagen, resultado de la convolucion de la original con la muestra a la respuesta unitaria.

CON UNA RESPUESTA A LA MUESTRA:h[n] =[1/500,1/500,1/500]

Page 8: Convolucion

Imagen original

Imagen después de la convolución(1/500).

Page 9: Convolucion

>> x=imread('C:\Dark.jpg');>> h =[1/1000,1/1000,1/1000];>> y=convn(x,h);>> imwrite(y,'C:\Darkreponse4.jpg');

CON UNA RESPUESTA A LA MUESTRA:h[n] =[1/1000,1/1000,1/1000]

Page 10: Convolucion

Imagen original

Imagen tras convolución (1/1000).

Page 11: Convolucion

COMPARANDO LAS IMAGENES

IMAGEN ORIGINAL

1/321/300

1/5001/1000

Page 12: Convolucion

USO DE MATLAB

PARA HACER UNA

CONVOLUCION DE

UN ARCHIVO DE

SONIDO

Page 13: Convolucion

FORMA DEL AUDIO ORIGINAL ES LA SIGUIENTE

0 2 4 6 8 10 12

x 105

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1AUDIO ORIGINAL

Page 14: Convolucion

RESPUESTA A LA MUESTRA DE 1/300

CODIGO MATLAB

>> A=wavread('C:\Blackbird');>> x1=[1/2,1/2,1/2,1/2,1/2];>> M=convn(A,x1);>> wavwrite(M,20050,16,'C:\Blackbirdreponse');>> plot(M,‘r','linewidth',1),title('Convolucion1/2'),grid;

Page 15: Convolucion

0 2 4 6 8 10 12

x 105

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1Convolucion 1/2

Page 16: Convolucion

RESPUESTA A LA MUESTRA DE 1/6

CODIGO MATLAB

>> A=wavread('C:\Blackbird');>> x2=[1/6,1/6,1/6,1/6,1/6];>> E=convn(A,x2);>> wavwrite(E,20050,16,'C:\Blackbirdreponse2');>> plot(E,‘m','linewidth',1),title('Convolucion1/6'),grid;

Page 17: Convolucion

0 2 4 6 8 10 12

x 105

-0.4

-0.3

-0.2

-0.1

0

0.1

0.2

0.3

0.4Convolucion 1/6

Page 18: Convolucion

>> a=wavread('C:\Blackbird');>> x3=[1/20,1/20,1/20,1/20,1/20];>> G=convn(A,x3);>> wavwrite(G,20050,16,'C:\Blackbirdreponse3');>> plot(G,‘b','linewidth',1),title('Convolucion1/20'),grid;

RESPUESTA A LA MUESTRA DE 1/20

CODIGO MATLAB

Page 19: Convolucion

0 2 4 6 8 10 12

x 105

-0.1

-0.08

-0.06

-0.04

-0.02

0

0.02

0.04

0.06

0.08

0.1Convolucion 1/20

Page 20: Convolucion

RESPUESTA A LA MUESTRA DE 1/32

CODIGO MATLAB

>> A=wavread('C:\Blackbird');>> x1=[1/32,1/32,1/32,1/32,1/32];>> M=convn(A,x1);>> wavwrite(M,20050,16,'C:\Blackbirdreponse');>> plot(M,'r','linewidth',1),title('Convolucion1/32'),grid;

Page 21: Convolucion

0 2 4 6 8 10 12

x 105

-0.08

-0.06

-0.04

-0.02

0

0.02

0.04

0.06

0.08Convolucion 1/32

Page 22: Convolucion

COMPARANDO SIMULTANEAMENTE LAS GRAFICAS

subplot(4,1,1),plot(M,‘r'),title('Convolucion1/2’),grid;subplot(4,1,2),plot(E,‘m'),title('Convolucion1/6'),grid;subplot(4,1,3),plot(G,‘b'),title('Convolucion1/20'),grid;subplot(4,1,4),plot(m,‘y'),title('Convolucion1/32'),grid;

Page 23: Convolucion

COMPARANDO SEÑALES

0 2 4 6 8 10 12

x 105

-101

Convolucion 1/2

0 2 4 6 8 10 12

x 105

-0.50

0.5Convolucion 1/6

0 2 4 6 8 10 12

x 105

-0.10

0.1Convolucion 1/20

0 2 4 6 8 10 12

x 105

-0.10

0.1Convolucion 1/32

Page 24: Convolucion

SUPERPONIENDO LAS GRAFICAS Y COMPARANDOLA CON LA ORIGINAL

>>plot(A,‘k','linewidth', 1),title('Comparacion del Audio Original y las Convoluciones'),grid; hold on;>>plot(M,‘r'); hold on;>>plot(E,‘m'); hold on;>> plot(G,’b');hold on;>>plot(m,‘y');

Page 25: Convolucion

SUPERPONIENDO SEÑALES

0 2 4 6 8 10 12

x 105

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1Comparacion del Audio Original y las Convoluciones