Advertisement
makispaiktis

Tutorial - Blur Lena Image

Aug 10th, 2021 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.84 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % MAIN FUNCTION
  5. A = imread('lena.png');
  6. filter = gaussianFilter(25, 5);     % I need a filter that has smaller dimensions than the photo
  7. figure();
  8. % I need a 2D signal-channel
  9. redChannel = A(:, :, 1);
  10. denominatorList = [1e2, 500, 1e3, 5000, 1e4, 5*1e4, 1e5];
  11. for i = 1:length(denominatorList)
  12.     denominator = denominatorList(i)
  13.     newImage = conv2(double(redChannel), filter / denominator);             % Typecast: uint8 ----> double
  14.     imshow(newImage);
  15.     caption = strcat('Filter divided by:', num2str(denominator))
  16.     title(caption);
  17. end
  18.  
  19.  
  20. % My gaussian filter
  21. function H = gaussianFilter(n, sigma)
  22.     twoSigmaSquared = 2*sigma*sigma;
  23.     for i =1:n
  24.         for j=1:n
  25.             x = i - n/2;
  26.             y = j - n/2;
  27.             H(i, j) = exp(-(x^2+y^2) / twoSigmaSquared);
  28.         end
  29.     end
  30.     H;
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement