Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OutputImage = Convolve3X3(InputImage, RowCount, ColCount, Kernel_x, Kernel_y)
- % Create a padded image
- PaddedImage = uint8(zeros(RowCount + 2, ColCount + 2));
- % Create a staging area
- StagingImage = uint8(zeros(RowCount + 2, ColCount + 2));
- % Create a Row Vector
- RowVector = uint8(zeros(1,3));
- % Create a Col Vector
- ColVector = uint8(zeros(3,1));
- % Copy the input image into the padded image
- PaddedImage(2:RowCount + 1, 2:ColCount + 1) = InputImage;
- % 1D convolution of necessary rows with Kernel_x
- for i = 2: RowCount + 1
- for j = 1:ColCount
- RowVector = PaddedImage(i,j:j+2) .* Kernel_x;
- StagingImage(i,j) = RowVector(1) + RowVector(2) + RowVector(3);
- end
- end
- % 1D convolution of necessary columns with Kernel_y
- for i = 1: RowCount
- for j = 1:ColCount
- ColVector = StagingImage(i:i+2,j) .* Kernel_y;
- OutputImage(i,j) = ColVector(1) + ColVector(2) + ColVector(3);
- end
- end
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement