Apply a CNN-style two-dimensional filter to a single-channel image. Pad every side with zeros, then slide the kernel with the supplied stride. Do not flip the kernel.
Yi,j=a=0∑Kh−1b=0∑Kw−1Xis+a,js+bpadKa,b Hout=⌊sH+2p−Kh⌋+1 Wout=⌊sW+2p−Kw⌋+1Here, X is the image, K is the kernel, s is stride, and p is padding. Return the output as a two-dimensional list of numbers.
Input: image = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], kernel = [[1, 0], [0, 1]], stride = 1, padding = 0
Output: [[6, 8], [12, 14]]
Explanation: Each output is the sum along the main diagonal of its two-by-two image patch.
Input: image = [[1, 2], [3, 4]], kernel = [[1, 1], [1, 1]], stride = 1, padding = 1
Output: [[1, 3, 2], [4, 10, 6], [3, 7, 4]]
Build a zero-filled padded grid and copy the image into its center.
Use four loops for output rows, output columns, kernel rows, and kernel columns.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Apply a CNN-style two-dimensional filter to a single-channel image. Pad every side with zeros, then slide the kernel with the supplied stride. Do not flip the kernel.
Yi,j=a=0∑Kh−1b=0∑Kw−1Xis+a,js+bpadKa,b Hout=⌊sH+2p−Kh⌋+1 Wout=⌊sW+2p−Kw⌋+1Here, X is the image, K is the kernel, s is stride, and p is padding. Return the output as a two-dimensional list of numbers.
Input: image = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], kernel = [[1, 0], [0, 1]], stride = 1, padding = 0
Output: [[6, 8], [12, 14]]
Explanation: Each output is the sum along the main diagonal of its two-by-two image patch.
Input: image = [[1, 2], [3, 4]], kernel = [[1, 1], [1, 1]], stride = 1, padding = 1
Output: [[1, 3, 2], [4, 10, 6], [3, 7, 4]]
Build a zero-filled padded grid and copy the image into its center.
Use four loops for output rows, output columns, kernel rows, and kernel columns.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number