开发者

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 doubles or floats 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜