From: Mukeshwar on 21 Apr 2010 23:00 When adding gaussian noise to image i receive this error message and it only happens with some images. Heres the codes s= 128; % Size of each matrix to display n = 4; % number of rows and cols in the figure for M = 0:n-1 % no. of cycles on y-axis for N = 0:n-1 % no. of cycles on x-axis F = zeros(s); % F is the Fourier transform array ... % ... which is all zeros apart from a single element ... F(M + 1, N + 1 ) = 1; % at this point % ... and the symmetrical elements for the negative frequencies F(mod(-M, s) + 1, N + 1 ) = 1; F(M + 1, mod(-N, s) + 1) = 1; F(mod(-M, s) + 1, mod(-N, s) + 1) = 1; % Now it's set up, do the inverse FT imcomp = ifft2(F); % f is the Fourier component in the spatial domain subplot(n, n, n*M + N + 1); imshow(imcomp, []); end end im=imread('5w','jpg'); im = im(1:2:397, 1:2:568); figure; imshow(im); F=fft2(im); figure; imshow(log(abs(F)), []); nx = size(F, 2); ny = size(F, 1); cxrange = [0:nx/2, -nx/2+1:-1]; % cycles across the image cyrange = [0:ny/2, -ny/2+1:-1]; [cx, cy] = meshgrid(cxrange, cyrange); fxrange = cxrange * 2*pi/nx; % radians per pixel fyrange = cyrange * 2*pi/ny; [fx, fy] = meshgrid(fxrange, fyrange); figure; cycles = [0 1 2 4 8]; n = length(cycles); for p = 1:n for q = 1:n keep = abs(cx) <= cycles(p) & abs(cy) <= cycles(q); partF = F .* keep; partim = ifft2(partF); subplot(n, n, n*(p-1) + q); imshow(partim); end end sigma = 0.09; % Width of the Gaussian, in radians/pixel ms = exp(-(fx.^2 + fy.^2)/(2*sigma^2)); figure; imshow(log(ms), []); smoothF = F .* ms; % multiply FT by mask smooth = ifft2(smoothF); % do inverse FT imshow(smooth, []); it works fine for some images but smaller images it crashes and gives ? Error using ==> times Matrix dimensions must agree" Please help
|
Pages: 1 Prev: Problem with Next: Can I compile my m-file into machine code ? |