You just need to cast the data to double
, then run your code again. Basically what the error is saying is that you are trying to mix classes of data together when applying a matrix multiplication between two variable. Specifically, the numerical vectors and matrices you define in dft1
are all of a double
type, yet your image is probably of type uint8
when you read this in through imread
. This is why you're getting that integer error because uint8
is an integer class and you are trying to perform matrix multiplication with this data type with those of a double
data type. Bear in mind that you can mix data types, so long as one number is a single number / scalar. This is also what the error is alluding to. Matrix multiplication of varaibles that are not floating point (double
, single
) is not supported in MATLAB so you need to make sure that your image data and your DFT matrices are the same type before applying your algorithm.
As such, simply do:
I = imread('sample.jpg');
R = dft1(double(I));
Minor Note
This code is quite clever, and it (by default) applies the 1D DFT to all columns of your image. The output will be a matrix of the same size as I
where each column is the 1D DFT result of each column from I
.
This is something to think about, but should you want to apply this to all rows of your image, you would simply transpose I
before it goes into dft1
so that the rows become columns and you can operate on these new "columns". Once you're done, you simply have to transpose the result back so that you'll get your output from dft1
shaped such that the results are applied on a per row basis. Therefore:
I = imread('sample.jpg');
R = dft1(double(I.')).';
Hope this helps! Good luck!