Quadrilateral and zero filling

I filter the image using a mask and Discret Fourier Trasform, so far 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 make a zero addition to the mask, but I do not know how to do this, please, I need help Thank you!

+4
source share
1 answer

what you want is called "padarray", immediately after defining 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 don't you just (given that A is a two-dimensional matrix, so rgb2gray if necessary):

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

This is faster because you do not need to multiply all these zeros and should get the same result.

+2
source

Source: https://habr.com/ru/post/1440445/


All Articles