Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I downloaded dftfilt that a function for image filtering in matlab! but it has some problem the following is code of that:

function g = dftfilt(f, H)
 F = fft2(f, size(H, 1), size(H, 2));
 g = real(ifft2(H.*F));
 g = g(1:size(f,1),1:size(f,2));


but in line 3 gives me an error that says: Error using .* Matrix dimensions must agree.

Error in dftfilt (line 3) g = real(ifft2(H.*F));

how can I fix this error? :( please help me thanks

What I have tried:

function g = dftfilt(f, H)
 F = fft2(f, size(H, 1), size(H, 2));
 g = real(ifft2(H.*F));
 g = g(1:size(f,1),1:size(f,2));
Posted
Updated 18-May-16 7:03am
Comments
Sergey Alexandrovich Kryukov 18-May-16 11:23am    
Multiplication of matrices of arbitrary dimension is not defined. The height of one must match the width of another one. More exactly... please see Solution 1.
—SA
Matt T Heffron 18-May-16 13:04pm    
I think this might be an issue with the wrong multiplication operator in Matlab. See my Solution.

In matlab the .* operator is an element-by-element multiplication.
The matrices must be the same dimensions.
If you intended a true matrix multiplication then just use the * operator, and the matrices must have the correct relative dimensions as noted in the Wikipedia article quoted by Sergey.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-May-16 13:09pm    
I see, thank you; 5ed.
—SA
Matt T Heffron 18-May-16 15:49pm    
Thank you
Multiplication of matrices of arbitrary dimension is not defined. The height of one must match the width of another one.

Matrix multiplication is extremely simple (in contrast to division/inversion). Please see, for example:
Matrix multiplication — Wikipedia, the free encyclopedia[^].
Pay attention,
This article tells you:

…if A is an n × m matrix and B is an m × p matrix, their matrix product AB is an n × p matrix, in which the m entries across the rows of A are multiplied with the m entries down the columns of B.
Also note that this is said about the product AB, in the given order. If n≠m or m≠p, multiplication BA is not defined, only AB product can be calculated. Matrix multiplication operator (even for p≡m≡n) is not commutative.

—SA
 
Share this answer
 
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900