Data sets from image

3 次查看(过去 30 天)
Brenden
Brenden 2011-6-7
I am new to Matlab and I have a jpg image that I have loaded. the image is not shown as data points that are plotted... not sure if this makes sense.. you can display the image with imshow.
what i am wanting to do is take the fourier transform and multiply the image by functions of my choosing however i dont know how to go about doing this as the image dosnt seem to be displayed as "data points" per say??

采纳的回答

Jonas Reber
Jonas Reber 2011-6-7
does it help if I provide you the following code as an example...?
%%Two Dimensional DFT Example
% 1.Load the sample image HeadCT.jpg, calculate its 2D DFT and plot the
% Fourier spectrum (increase its contrast if necessary) and phaseangles.
img=double(imread('HeadCT.jpg'));
figure, imshow(img,[]);
IMG=fftshift(fft2(img));
logspect=log(1+abs(IMG));
theta=angle(IMG);
figure
subplot(1,2,1);
imshow(theta,[]);title('Phase');
subplot(1,2,2);
imshow(logspect,[]);title('Spectrum');
% 2.Calculate the 2D Fourier transformation of the sample image using only
% the 1D Fourier transform fft().
IMG2=fftshift( fft(fft(img).').' );
max(max(abs(IMG-IMG2)))
% 3.Keep the phase of the Fourier transform and replace the magnitude of
% each frequency sample by its square root. Take the inverse DFT.
spect=sqrt(abs(IMG));
Z=spect.*exp(i*theta);
z=abs(ifft2(fftshift(Z)));
figure, imshow(z,[]);
% what do you see?
% the operation enhanced the edges. the reason being, that the low
% frequencies with lots of energy thus having an amplitude>1 are damped.
% The high frequencies on the other hand generally have little energy,
% i.e. amplitude<1, and are therefore enhanced by the sqrt.
% 4.Set the magnitude and phase of the high frequencies to zero and
% take the inverse DFT, and explain what you see.
[M N]=size(img);
u=0:M-1;
v=0:N-1;
%
idx=find(u>M/2);
u(idx)=u(idx)-M;
idx=find(v>N/2);
v(idx)=v(idx)-N;
%
[U,V]=meshgrid(v,u);
D=fftshift(sqrt(U.^2+V.^2));
mesh(D);
%
Z=IMG.*(D<75);
z=abs(ifft2(fftshift(Z)));
figure, imshow(z,[0 255]);
% setting the high frequencies to 0 equals a low pass filter
  5 个评论
Jonas Reber
Jonas Reber 2011-6-7
exactly. if you have a grayscale image (IMG) of size MxN you can access the pixels IMG(y,x) (where y=1..N and x=1..M)
note. x and y are changed as indeces are handeled row x column.
M = 200; % the real width of the image
N = 100; % the real height of the image
IMG = zeros(N,M);
% put a white line to the half of the image,
% top left corner to center of left edge
IMG(1:end/2,1) = 1;
% put a gray square to the center of the image
IMG(end/2-10:end/2+10,end/2-5:end/2+5) = 0.5;
% put a horizontal line on the right side of the image
IMG(end/2,end/2:end) = 0.8;
imshow(IMG,[]);
it's basically just important to remember that x and y somehow seem to be changed :) as we are used to think in an x first way when we talk about images...
Brenden
Brenden 2011-6-7
This has been great help

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by