PIXELBANKv8.2.1
Menu

Flip image

Implement a function to manipulate a given n×nn \times n binary image matrix, flipping it horizontally and then inverting it. The goal is to understand how image transformation and binary inversion work together to produce the resulting image. In image processing, flipping an image horizontally involves reversing the order of elements in each row, which can be represented as [a,b,c][a, b, c] becoming [c,b,a][c, b, a]. Here are the steps to achieve this:

  1. Iterate over each row in the image matrix.
  2. Reverse the order of elements in each row.
  3. Invert each element in the row, replacing 00 with 11 and 11 with 00.
f(x)=1x\begin{aligned} f(x) &= 1 - x \end{aligned}

This technique is widely used in data augmentation for training machine learning models.

Example:

Input:
image = [[1,1,0],[1,0,1],[0,0,0]]
Output:
Output: [[1,0,0],[0,1,0],[1,1,1]]
Reasoning:
  • First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
  • Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]

Constraints:

n == image.length n == image[i].length 1 <= n <= 20

Editor

Test Results

0/0
Run code to see test results.