您的位置:首页 > 编程语言 > MATLAB

Projection the 2D spectrum of an image to 1D with MATLAB

2014-01-09 23:38 344 查看
I = imread('cameraman.tif');
imagesc(I); colormap gray; title('Original image'); pause;

% Fourier transform
F = ifftshift(fft2(I))./rows./cols;

% Show spectrum (log)
imagesc(log(abs(F))); title('Fourier transform (abs log)'); pause;

% Grid of FFT coordinates
[rows, cols] = size(F);
[ux, uy] = meshgrid(([1:cols]-(fix(cols/2)+1))/(cols-mod(cols,2)), ...
([1:rows]-(fix(rows/2)+1))/(rows-mod(rows,2)));

% Convert to polar coordinates
th = atan2(uy,ux);
r = sqrt(ux.^2 + uy.^2);

% Convert to polar coordinates
Fr = F .* r;
imagesc(abs(Fr)); title('Fourier transform x radius'); pause;
rcoords = linspace(0,sqrt(ux(1,1)^2 + uy(1,1)^2),rows);
thcoords = linspace(0,2*pi,cols);
[ri,thi] = meshgrid(rcoords,thcoords);
[x,y] = pol2cart(thi,ri);
Fp = interp2(ux,uy,abs(Fr),x,y);
imagesc(Fp); title('Fourier transform in polar coordinates'); pause;

% Sum columns to give 1D projection
F1D = sum(Fp);
plot(rcoords,F1D); title('Projection onto 1D'); xlim([0 0.5]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐