Get Started with Image Preprocessing and Augmentation for Deep Learning - MATLAB & Simulink (original) (raw)

Main Content

Data preprocessing consists of a series of deterministic operations that normalize or enhance desired data features. For example, you can normalize data to a fixed range or rescale data to the size required by the network input layer. Preprocessing is used for training, validation, and inference.

Preprocessing can occur at two stages in the deep learning workflow.

Data augmentation consists of randomized operations that are applied to the training data while the network is training. Augmentation increases the effective amount of training data and helps to make the network invariant to common distortion in the data. For example, you can add artificial noise to training data so that the network is invariant to noise.

To augment training data, start by loading your data into a datastore. Some built-in datastores apply a specific and limited set of augmentation to data for specific applications. You can also apply your own set of augmentation operations on data in the datastore by using the transform andcombine functions. During training, the datastore randomly perturbs the training data for each epoch, so that each epoch uses a slightly different data set. For more information, seePreprocess Images for Deep Learning and Preprocess Volumes for Deep Learning.

Preprocess and Augment Images

Common image preprocessing operations include noise removal, edge-preserving smoothing, color space conversion, contrast enhancement, and morphology.

Augment image data to simulate variations in the image acquisition. For example, the most common type of image augmentation operations are geometric transformations such as rotation and translation, which simulate variations in the camera orientation with respect to the scene. Color jitter simulates variations of lighting conditions and color in the scene. Artificial noise simulates distortions caused by the electrical fluctuations in the sensor and analog-to-digital conversion errors. Blur simulates an out-of-focus lens or movement of the camera with respect to the scene.

You can process and augment image data using the operations in this table, as well as any other functionality in the toolbox. For an example that shows how to create and apply these transformations, see Augment Images for Deep Learning Workflows.

Processing Type Description Sample Functions Sample Output
Resize images Resize images by a fixed scaling factor or to a target size imresize, imresize3 The original image is on the left, and a resized image is on the right.
Crop images Crop an image to a target size from the center or a random position centerCropWindow2d, centerCropWindow3drandomWindow2d, randomCropWindow3d An image cropped from the center is on the left, and an image cropped from a random position is on the right.
Warp images Apply random reflection, rotation, scale, shear, and translation to images randomAffine2d, randomAffine3d From left to right, the figure shows the original image and the resulting images after reflection, rotation, and scaling.
Jitter color Randomly adjust image hue, saturation, brightness, or contrast of color images jitterColorHSV From left to right, the figure shows the original image with random adjustments to the image hue, saturation, brightness, and contrast.
Simulate noise Add random Gaussian, Poisson, salt and pepper, or multiplicative noise imnoise An image with randomly added salt and pepper noise is on the left, and an image with randomly added Gaussian noise is on the right.
Simulate blur Add Gaussian or directional motion blur imgaussfilt, imgaussfilt3imfilter An image with a Gaussian blur is on the left, and an image with a directional motion blur is on the right.
Jitter intensity Randomly adjust the brightness, contrast, or gamma correction of grayscale images and volumes jitterIntensity (Medical Imaging Toolbox) From left to right, the figure shows the original image with random adjustments to the brightness, contrast, and gamma correction.

Preprocess and Augment Pixel Label Images for Semantic Segmentation

Semantic segmentation data consists of images and corresponding pixel labels represented as categorical arrays. For more information, see Get Started with Semantic Segmentation Using Deep Learning (Computer Vision Toolbox).

If you have Computer Vision Toolbox™, then you can use the Image Labeler (Computer Vision Toolbox) and the Video Labeler (Computer Vision Toolbox) apps to interactively label pixels and export the label data for training a neural network.

When you transform an image for semantic segmentation, you must perform an identical transformation to the corresponding pixel labeled image. You can preprocess pixel label images using the functions in the table and any other function that supports categorical input. For an example that shows how to create and apply these transformations, seeAugment Pixel Labels for Semantic Segmentation (Computer Vision Toolbox).

See Also

Topics