Advertisement
Shailrshah

DFT of a 2-D image using matrix multiplication

Oct 11th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.48 KB | None | 0 0
  1. clc; clear all;
  2. %x = [0 1 2 1; 1 2 3 2; 2 3 4 3; 1 2 3 2];
  3. x = double(imread('cameraman.tif'));
  4. n = length(x);
  5.  
  6. DFT_matrix = exp(-2i * pi / n * [0:n-1]' * [0:n-1])
  7. %DFT_matrix = [1 1 1 1; 1 -i -1 i; 1 -1 1 -1; 1 i -1 -i];
  8.  
  9. step1=zeros(n);
  10. for i=1:n %Row multiplications
  11.     step1(i, :) = DFT_matrix*x(i, :)';
  12. end
  13.  
  14. step2=zeros(n);
  15. for i=1:n %Col multiplications
  16.    step2(:, i) = DFT_matrix*Step1(:,i);
  17. end
  18.  
  19. figure(1), imshow(uint8(x));
  20. figure(2), imshow(uint8(Step2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement