Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

66. Image augmentation transforms

easy
GeneralGeneral
senior

Image augmentation applies simple transforms to images to create more training examples and help computer vision models generalize better.

A common augmentation pipeline might include horizontal flips, brightness scaling, and random cropping, each applied in a controlled way.

Requirements

Implement the function

python

Rules:

  • Apply transforms strictly in the order: flip → brightness → crop.
  • Horizontal flip means reversing the columns: [:, ::-1].
  • Brightness scaling uses the formula p′=pâ‹…bp' = p \cdot b for each pixel value p and factor b.
  • Cropping uses crop = [top, left, height, width] and returns the sub-image.
  • Use only NumPy.

Example

python

Output:

python
Input Signature
ArgumentType
imgnp.ndarray
croplist
flipint
brightnessfloat
Output Signature
Return NameType
valuenp.ndarray

Constraints

  • Use only NumPy.

  • Do not use libraries like PIL, OpenCV, etc.

Hint 1

For horizontal flip, you can reverse the columns using NumPy slicing: img[:, ::-1].

Hint 2

Brightness is just element-wise multiplication: img * brightness.

Hint 3

Cropping is 2D slicing: img[top:top+height, left:left+width].

Roles
ML Engineer
AI Engineer
Companies
GeneralGeneral
Levels
senior
entry
Tags
image-augmentation
2d-list-processing
array-slicing
list-comprehensions
43 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit