📘
Flip image
EasyLinear Algebra
Implement a function to manipulate a given n×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] becoming [c,b,a]. Here are the steps to achieve this:
- Iterate over each row in the image matrix.
- Reverse the order of elements in each row.
- Invert each element in the row, replacing 0 with 1 and 1 with 0.
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
Python 3.13.1
Test Results
0/0Run code to see test results.