Main Content

crop2dLayer

2-D crop layer

Description

A 2-D crop layer applies 2-D cropping to the input.

There are two inputs to this layer:

  • 'in' — The feature map that will be cropped

  • 'ref' — A reference layer used to determine the size, [height width], of the cropped output

Once you create this layer, you can add it to a layerGraph to make serial connections between layers. To connect the crop layer to other layers, call connectLayers and specify the input names. The connectLayers function returns a connected LayerGraph object ready to train a network.

Creation

Description

layer = crop2dLayer(Mode) returns a layer that crops an input feature map, and sets the Mode property.

layer = crop2dLayer(Location) returns a layer that crops an input feature map using a rectangular window, and sets the Location property that indicates the position of the window.

example

layer = crop2dLayer(___,'Name',Name) creates a layer for cropping and sets the optional Name property.

Properties

expand all

Cropping mode, specified as 'centercrop' or 'custom'.

ModeDescription
'centercrop'The location of the cropping window is the center of the input feature map.
'custom'The location of the cropping window is based on the Location property. This value is automatically set when the Location property is specified as a 2-element row vector.

Data Types: char

Cropping window location, specified as 'auto' or a 2-element row vector.

LocationDescription

2-element row vector in the format [x y]

The upper-left corner of the cropping window is at the location [x y] of the input feature map. x indicates the location in the horizontal direction and y is the vertical direction.

'auto'The cropping window is located at the center of the input feature map. This value is automatically set when the Mode property is specified as 'centercrop'.

Layer name, specified as a character vector or a string scalar. To include a layer in a layer graph, you must specify a nonempty unique layer name. If you train a series network with the layer and Name is set to '', then the software automatically assigns a name to the layer at training time.

Data Types: char | string

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

Data Types: double

Input names of the layer. This layer has two inputs, named 'in' and 'ref'.

Data Types: cell

Number of outputs of the layer. This layer has a single output only.

Data Types: double

Output names of the layer. This layer has a single output only.

Data Types: cell

Examples

collapse all

Create a 2-D crop layer and connect both of the inputs using a layerGraph object.

Create the layers.

layers = [
     imageInputLayer([32 32 3],'Name','image')
     crop2dLayer('centercrop','Name','crop')]
layers = 
  2x1 Layer array with layers:

     1   'image'   Image Input   32x32x3 images with 'zerocenter' normalization
     2   'crop'    Crop 2D       center crop

Create a layerGraph. The first input of crop2dLayer is automatically connected to the first output of the image input layer.

lgraph = layerGraph(layers)
lgraph = 
  LayerGraph with properties:

         Layers: [2x1 nnet.cnn.layer.Layer]
    Connections: [1x2 table]
     InputNames: {'image'}
    OutputNames: {1x0 cell}

Connect the image input layer to the "ref" input of the 2-D crop layer.

lgraph = connectLayers(lgraph,'image','crop/ref')  
lgraph = 
  LayerGraph with properties:

         Layers: [2x1 nnet.cnn.layer.Layer]
    Connections: [2x2 table]
     InputNames: {'image'}
    OutputNames: {1x0 cell}

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

See Also

| | (Computer Vision Toolbox) | (Computer Vision Toolbox) | (Computer Vision Toolbox) | (Computer Vision Toolbox) | (Computer Vision Toolbox) | (Computer Vision Toolbox)

Introduced in R2017b