tensorflowdeeplab

Blur and Motion Blur augmentation


I am using Deeplabv3+ repository and I would like to know how do you apply Motion Blur and Blur as augmentation. I have a few augmentations already, like random scale (example).

However, I could not find any out of the box solution to apply Motion Blur on tensorflow. Does anyone know any library or how to build this transformation?

def randomly_scale_image_and_label(image, label=None, scale=1.0):
  """Randomly scales image and label.

  Args:
    image: Image with shape [height, width, 3].
    label: Label with shape [height, width, 1].
    scale: The value to scale image and label.

  Returns:
    Scaled image and label.
  """
  # No random scaling if scale == 1.
  if scale == 1.0:
    return image, label
  image_shape = tf.shape(image)
  new_dim = tf.cast(
      tf.cast([image_shape[0], image_shape[1]], tf.float32) * scale,
      tf.int32)

  # Need squeeze and expand_dims because image interpolation takes
  # 4D tensors as input.
  image = tf.squeeze(tf.image.resize_bilinear(
      tf.expand_dims(image, 0),
      new_dim,
      align_corners=True), [0])
  if label is not None:
    label = tf.squeeze(tf.image.resize_nearest_neighbor(
        tf.expand_dims(label, 0),
        new_dim,
        align_corners=True), [0])

  return image, label

Solution

  • There is a very good library called albumentations.

    You can have a look here: https://github.com/albumentations-team/albumentations/blob/master/notebooks/example.ipynb.

    I am sure it will be of great usage; it contains all sorts of augmentations, for different use cases(object detection, image segmentation).