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 dlnetwork object to make serial connections between layers. To connect the crop layer to other layers, use connectLayers and specify the input names.

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.

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

example

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 string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign names to layers with the name "".

The Crop2DLayer object stores this property as a character vector.

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

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

Examples

collapse all

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

Create a dlnetwork object.

net = dlnetwork;

Specify the layers and add them to the network.

layers = [
     imageInputLayer([32 32 3],'Name','image')
     crop2dLayer('centercrop','Name','crop')];
net = addLayers(net,layers);

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

net = connectLayers(net,'image','crop/ref')
net = 
  dlnetwork with properties:

         Layers: [2x1 nnet.cnn.layer.Layer]
    Connections: [2x2 table]
     Learnables: [0x3 table]
          State: [0x3 table]
     InputNames: {'image'}
    OutputNames: {'crop'}
    Initialized: 0

  View summary with summary.

Algorithms

expand all

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™.

Version History

Introduced in R2017b

expand all

See Also

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