"Image" (Net Encoder)

NetEncoder["Image"]

represents an encoder that converts a 2D image to a rank-3 tensor of pixel values.

NetEncoder[{"Image",size}]

represents an encoder that resizes the input image to size.

NetEncoder[{"Image",{width,height}}]

represents an encoder that resizes the input image to the specified dimensions.

NetEncoder[{"Image",size,"param"val,}]

represents an encoder with specific parameters for preprocessing.

Details

  • NetEncoder[][input] applies the encoder to an input to produce an output.
  • NetEncoder[][{input1,input2,}] applies the encoder to a list of inputs to produce a list of outputs.
  • The input to the encoder can be an Image[] object or a File[] expression.
  • NetEncoder["Image"] is equivalent to NetEncoder[{"Image",{128,128}}].
  • An encoder can be attached to an input port of a net by specifying "port"->NetEncoder[] when constructing the net.
  • Parameters
  • The following parameters are supported:
  • ColorSpace"RGB"color space to use for encoding
    InterleavingFalsewhether channels are interleaved
    "MeanImage"Nonemean image to subtract
    "VarianceImage"Nonevariance image to normalize by
  • The parameter ColorSpace can take the same values as the ColorSpace option.
  • The output of the encoder is a rank-3 array of dimensions {c,height,width} when InterleavingFalse and {height,width,c} when InterleavingTrue, where c is the number of color channels.
  • The following settings can be used for "MeanImage" and "VarianceImage":
  • Nonedo not subtract anything
    mvalue to subtract from each pixel
    {m1,m2,}values to be subtracted from different channels
    Image[]overall image to subtract
  • Pixels are normalized to lie between 0 and 1 before doing subtraction.

Examples

open allclose all

Basic Examples  (1)

Create an image encoder of a specified size:

Encode an image:

Scope  (1)

NetEncoder["Image"] can encode either File or Image objects. Create an image encoder:

Apply the encoder to a File object:

Apply the encoder to an Image object:

Apply the encoder to a list of images:

Parameters  (4)

ColorSpace  (1)

Set the ColorSpace of the output image to "Grayscale":

The output NumericArray only has one channel dimension, appropriate for grayscale images.

Interleaving  (1)

With InterleavingFalse, the channel dimension of the output is the first dimension in the dimensions list:

With InterleavingTrue, the channel dimension of the output is the last dimension in the dimensions list:

"MeanImage"  (1)

Create an image encoder that subtracts a list of mean values from the encoded image:

Create an image with every pixel value being 0.8:

Apply the encoder to the image:

This is equivalent to:

"VarianceImage"  (1)

Create an image encoder that normalizes the encoded image by a list of variances:

Create an image with every pixel value being 0.8:

Apply the encoder to the image:

This is equivalent to:

Properties & Relations  (1)

When applying an image encoder to a list of File objects, NetEncoder will attempt to parallelize the computation on multi-core processors. Create a list of 64 images:

Create an image encoder:

Show the number of available processors:

Map the encoder over the images:

To exploit parallelism, apply the encoder to a list of File objects directly rather than with Map:

Introduced in 2018
 (11.3)
 |
Updated in 2019
 (12.0)