Borrar filtros
Borrar filtros

Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar.

33 visualizaciones (últimos 30 días)
I'm trying to implement a 1 dimensional DFT without using Matlab built-in functions such as fft(). This is my code:
function [Xk] = dft1(xn)
N=length(xn);
n = 0:1:N-1; % row vector for n
k = 0:1:N-1; % row vecor for k
WN = exp(-1j*2*pi/N); % Twiddle factor (w)
nk = n'*k; % creates a N by N matrix of nk values
WNnk = WN .^ nk; % DFT matrix
Xk = (WNnk*xn );
when i run the code after using the following commands:
I = imread('sample.jpg')
R = dft1(I)
I get this particular error: *Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar. To compute elementwise TIMES, use TIMES (.*) instead.*
Can someone please help me to figure out how to solve this problem
Note: I am still in the very beginning level of learning Matlab. Thank you very much

Respuesta aceptada

Star Strider
Star Strider el 30 de Nov. de 2014
To do an FFT you need to start by converting it to grayscale:
I = imread('sample.jpg');
G = double(rgb2gray(I));
Note that to take the FFT of a matrix M, you need to take the FFT of the transpose of the first FFT, that is
FFT(M) = FFT(FFT(M).').'
The dot operator here (.') takes the simple (not complex conjugate) transpose.
  2 comentarios
alladin
alladin el 30 de Nov. de 2014
Thank you for your help; however, I'm trying to implement 1 dimensional dft here without using matlab built-in functions. can you please help me resolve the issue?
Star Strider
Star Strider el 30 de Nov. de 2014
Editada: Star Strider el 30 de Nov. de 2014
My pleasure.
I used ‘FFT’ in the generic sense. I haven’t run your code, but it should produce a matrix as output on the first pass, taking the first Fourier transform of ‘G’. You then need to take the simple transpose of that output matrix and do the Fourier transform on it. That output is the Fourier transform of your image.

Iniciar sesión para comentar.

Más respuestas (1)

Guillaume
Guillaume el 30 de Nov. de 2014
Editada: Guillaume el 30 de Nov. de 2014
Your jpg image is read as integer ( uint8 most likely) and matlab is not that good at manipulating pure integers as per the error message. The simplest way to solve this is to convert the integers to doubles:
I = double(imread('sample.jpg'));
  3 comentarios
Guillaume
Guillaume el 30 de Nov. de 2014
It looks like your code assume a square matrix whereas your image is not square.
The reason I say it looks like you assume a square matrix, is because of this line:
N = length(xn);
length returns the size of the largest dimension, and you then use that to build an N*N matrix. If your input is M*N (M<N) you can't multiply it with your Wnk.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by