2D convolution is a fundamental operation in digital image processing, computer vision, and deep learning. The aim of this problem is to implement 2D convolution through programming, further consolidating your understanding and application of parallel computing, thread cooperation, and shared memory.
2D convolution is one of the most basic and important operations in digital image processing. Essentially, it uses a small matrix known as a convolution kernel or filter, to compute a weighted sum over each pixel and its neighborhood in the image. This operation enables effects like image smoothing, sharpening, and edge detection, and serves as the foundation for many advanced image processing algorithms.
From a mathematical perspective, the 2D discrete convolution operation can be expressed as follows: for an input image
Here, the ranges of
Input: Kernel: Output:
┌─────────┐ ┌──────┐ ┌───────┐
│ 1 2 3 │ │ 1 1 │ │ 12 15 │
│ 4 5 6 │ * │ 1 1 │ = │ 24 28 │
│ 7 8 9 │ └──────┘ └───────┘
└─────────┘
If no special handling is done at the boundaries, the output image will be smaller than the input image (specifically, output size = input size - kernel size + 1). To keep the output image the same size as the input, it's common to add extra border pixels to the input image—a process known as padding. Padding can be done with zeros (zero-padding) or by mirroring (using values near the edge). In this problem, you are required to use zero-padding to handle the boundaries.
Tip: As with Problem 3, you can use shared memory to optimize your computation.
In the test data, the length and width of the convolution kernel may be any of make test to compile and run the tests.