%% Create Convolutional Layer That Fully Covers 3-D Input
% Suppose the size of the input is 28-by-28-by-28-by-1. Create a 3-D convolutional layer with 16 filters, each with a height of 6, a width of 4, and a depth of 5. Set the stride in all dimensions to 4.
% Make sure the convolution covers the input completely. For the convolution to fully cover the input, the output dimensions must be integer numbers. When there is no dilation, the i-th output dimension is calculated as (imageSize(i) - filterSize(i) + padding(i)) / stride(i) + 1.
% For the horizontal output dimension to be an integer, two rows of padding are required: (28 – 6 + 2)/4 + 1 = 7. Distribute the padding symmetrically by adding one row of padding at the top and bottom of the image.
% For the vertical output dimension to be an integer, no padding is required: (28 – 4+ 0)/4 + 1 = 7.
% For the depth output dimension to be an integer, one plane of padding is required: (28 – 5 + 1)/4 + 1 = 7. You must distribute the padding asymmetrically across the front and back of the image. This example adds one plane of padding to the back of the image.
% Construct the convolutional layer. Specify 'Padding' as a 2-by-3 matrix. The first row specifies prepadding and the second row specifies postpadding in the three dimensions.

layer = convolution3dLayer([6 4 5],16,'Stride',4,'Padding',[1 0 0;1 0 1])

% Copyright 2018 The MathWorks, Inc.