Flip an Image Horizontally or Vertically
Core Vision Operations DS practice problem on Onlearn.
Difficulty: easy.
Topics: Understanding Image Geometric Transformations, Row-major order indexing, Negative indexing in lists, Axis-based array reversal, Boundary condition handling, Stride-based data manipulation, Linear Algebra, Digital Image Processing, Array Manipulation, Coordinate Geometry, Computational Complexity, Matrix Transposition, Pixel Coordinate Mapping, Memory Layouts, Spatial Transformations, In-place vs Out-of-place Operations.
Implement a function that takes a 2D or 3D image array (represented as a list of lists or a NumPy array) and a flip mode (0 for vertical, 1 for horizontal). Return the flipped image. Handle the transformation without using external libraries like OpenCV if possible, or demonstrate the standard NumPy approach.