Main Content


3-D crop layer

Since R2019b


A 3-D crop layer crops a 3-D volume to the size of the input feature map.

Specify the number of inputs to the layer when you create it. The inputs to the layer have the names 'in' and 'ref'. Use the input names when connecting or disconnecting the layer by using connectLayers or disconnectLayers. All inputs to a 3-D crop layer must have the same number of dimensions.



layer = crop3dLayer creates a 3-D crop layer that crops an input feature map from the center of the feature map. The size of the cropped region is equal to the size of a second reference input feature map.

layer = crop3dLayer([X Y Z]) also sets the cropLocation property with the (X,Y,Z) coordinate of the crop window. X is the coordinate in the horizontal direction, Y is the coordinate in the vertical direction, and Z is the coordinate in the depth direction.


layer = crop3dLayer(___,'Name',Name) also sets the Name property. To create a network containing a 3-D crop layer, you must specify a layer name.


expand all


Crop location, specified as 'centercrop' or a three-element numeric vector representing the (x,y,z) coordinate of the crop window.


Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet, trainNetwork, assembleNetwork, layerGraph, and dlnetwork functions automatically assign names to layers with the name "".

The Crop3DLayer object stores this property as a character vector.

Data Types: char | string

Number of inputs of the layer. This layer accepts two inputs.

Data Types: double

Input names of the layer, specified as {'in','ref'}. This layer accepts two inputs.

Data Types: cell

This property is read-only.

Number of outputs from the layer, returned as 1. This layer has a single output only.

Data Types: double

This property is read-only.

Output names, returned as {'out'}. This layer has a single output only.

Data Types: cell


collapse all

Create a 3-D crop layer and connect both of its inputs using a layerGraph object.

layers = [
    image3dInputLayer([32 32 32 3],'Name','image')
layers = 
  4x1 Layer array with layers:

     1   'image'    3-D Image Input   32x32x32x3 images with 'zerocenter' normalization
     2   'conv'     3-D Convolution   16 3x3x3 convolutions with stride [1  1  1] and padding 'same'
     3   'crop'     Crop 3D           center crop
     4   'concat'   Concatenation     Concatenation of 2 inputs along dimension 4

Create a layer graph. The first input of the 3-D crop layer is automatically connected to the output of the 3-D convolutional layer.

lgraph = layerGraph(layers);

Add a max pooling layer to the layer graph.

maxPool = maxPooling3dLayer(2,'stride',2,'Name','pool');
lgraph = addLayers(lgraph,maxPool);
lgraph = connectLayers(lgraph,'image','pool');

Connect the second input of the crop layer to the output of the max pooling layer.

lgraph = connectLayers(lgraph,'pool','crop/ref');

Concatenate the crop layer output and the max pooling layer output.

lgraph = connectLayers(lgraph,'pool','concat/in2');

Display the layer graph.


Figure contains an axes object. The axes object contains an object of type graphplot.


expand all

Version History

Introduced in R2019b