简体   繁体   中英

matlab image processing error

I am trying to find the fourier transform of an image in matlab. I am doing this without the hep of the library function. The code is:

clc;
clear;
N=128; 
a=imread('lena128','bmp');
zeros(N,N);
for m=1:N
    for n=1:N
        w(m,n)=(exp(-1i*2*pi/N))^((m-1)*(n-1));
    end
end
af1=(w*a);
af=((w*(af1.')).');

When I compile this program the following error occurs:

??? Error using ==> mtimes
Complex integer arithmetic is not supported.
Error in ==> qn4 at 12
af1=(w*a);

When I use a=rand(1,128), instead of a=imread('lena128','bmp'), I dont get that error. I searched online and found similar problems. But no solution. Can anyone point out the error for me?

imread is giving you an array whose elements are integers (of type uint8 , I think). You're then trying to combine those with complex numbers, and that doesn't work. In particular, MATLAB will not automatically turn them into double s or float s or anything of the kind.

You should probably just say

a=double(imread('lena128','bmp'));

The imread function returns a matrix of uint8 elements for grayscale bmp images. Many MatLab functions and operations work on double elements only. Convert your image to a double matrix with im2double .

a=imread('lena128','bmp');
a=im2double(a);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM