Pregunta

I'm filtering an image using a mask and the Discret Fourier Trasform, till now i have this

A=double(imread('C:\Users\samsung\Documents\Lab Imagenes\CHE.jpg','jpg'));
B=[1 4 6 4 1; 4 16 24 16 4; 6 24 36 24 6; 4 16 24 16 4; 1 4 6 4 1];
F=(1/256).*(B);
DFT_A=fftshift(fft2(A));
imshow(DFT_A);
DFT_A_F=DFT_A.*F;
figure
imshow(DFT_A_F)

but when i want to see partial results I got this error

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> fourier1 at 10 
DFT_A_F=DFT_A.*F;

I know that i need to do zero padding to the mask, but i don't know how to do it, please I need help Thanks!

¿Fue útil?

Solución

what you want is called 'padarray' , just after you define DFT_A:

padsize= [round(0.5*size(DFT_A,1)-0.5*size(F,1)) round(0.5*size(DFT_A,2)-0.5*size(F,2))];
F = padarray(F, padsize);
DFT_A_F=DFT_A.*F;
...

But why won't you just (given that A is a 2D matrix, so rgb2gray it if needed):

DFT_A_F = conv2(A,B,'same');

It is faster, because you don't need to multiply all these zeros, and should get you the same result.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top