Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function OutputImage = Convolve3X3(InputImage, RowCount, ColCount, Kernel_x, Kernel_y)
  2.  
  3. % Create a padded image
  4. PaddedImage = uint8(zeros(RowCount + 2, ColCount + 2));
  5.  
  6. % Create a staging area
  7. StagingImage = uint8(zeros(RowCount + 2, ColCount + 2));
  8.  
  9. % Create a Row Vector
  10. RowVector = uint8(zeros(1,3));
  11.  
  12. % Create a Col Vector
  13. ColVector = uint8(zeros(3,1));
  14.  
  15. % Copy the input image into the padded image
  16. PaddedImage(2:RowCount + 1, 2:ColCount + 1) = InputImage;
  17.  
  18. % 1D convolution of necessary rows with Kernel_x
  19. for i = 2: RowCount + 1
  20. for j = 1:ColCount
  21. RowVector = PaddedImage(i,j:j+2) .* Kernel_x;
  22. StagingImage(i,j) = RowVector(1) + RowVector(2) + RowVector(3);
  23. end
  24. end
  25.  
  26. % 1D convolution of necessary columns with Kernel_y
  27. for i = 1: RowCount
  28. for j = 1:ColCount
  29. ColVector = StagingImage(i:i+2,j) .* Kernel_y;
  30. OutputImage(i,j) = ColVector(1) + ColVector(2) + ColVector(3);
  31. end
  32. end
  33.  
  34. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement