1
4 4
100 120 130 140
80 90 100 110
60 70 80 90
40 50 60 70
2
0 2
BRIGHTNESS 30
FLIP_V
0 1
THRESHOLD 1004 4
70 80 90 100
90 100 110 120
110 120 130 140
130 150 160 170
4 4
255 255 255 255
0 0 255 255
0 0 0 0
0 0 0 0Implement an ImageTransformer, a tool that can hold a set of images and apply some operations to transform them in various different ways.
You are given a sequence of grayscale images and a list of edit scripts. Each edit script is a sequence of named operations applied to one image to produce a new one. Your task is to apply each script and output the resulting image.
All images are grayscale. Each pixel is an integer in [0, 255]. Images are represented as H x W grids of integers. Pixel values are clamped to [0, 255] after every operation.
Each operation takes the current image as input and produces a new image of the same dimensions. Operations are applied in the order listed in the script. The output image is the result after all operations have been applied.
| Name | Arguments |
|---|---|
BRIGHTNESS |
d (integer) |
FLIP_H |
(none) |
FLIP_V |
(none) |
CROP |
r c h w |
ROTATE_90 |
(none) |
THRESHOLD |
t (integer) |
BRIGHTNESS d — Add d to every pixel.FLIP_H — Flip the image horizontally (mirror left-right).FLIP_V — Flip the image vertically (mirror top-bottom).CROP r c h w — Extract the h x w sub-image starting at row r, column c. All subsequent operations use this smaller image.ROTATE_90 — Rotate the image 90° clockwise.THRESHOLD t — Set each pixel to 255 if it is ≥ t, else 0.N
<image_0>
<image_1>
...
<image_(N-1)>
S
<script_0>
<script_1>
...
<script_(S-1)>Each image is given as:
H W
<row 0>
<row 1>
...
<row H-1>Each script is given as:
img_index K
op_1 [args]
op_2 [args]
...
op_K [args]where img_index is the 0-indexed image to apply the script to, and K is the number of operations.
For each script (in order), output the resulting image:
H W
<row 0>
...
<row H-1>with a blank line between images.
ROTATE_90 clockwise means row r, column c maps to row c, column (H-1-r) in the new image (new dimensions are W x H).img_index, not from the result of a previous script.1 ≤ N ≤ 201 ≤ S ≤ 501 ≤ H, W ≤ 1281 ≤ K ≤ 20CROP is always given valid arguments: r + h ≤ H and c + w ≤ W at the time of the crop.1 x 1.1
4 4
100 120 130 140
80 90 100 110
60 70 80 90
40 50 60 70
2
0 2
BRIGHTNESS 30
FLIP_V
0 1
THRESHOLD 1004 4
70 80 90 100
90 100 110 120
110 120 130 140
130 150 160 170
4 4
255 255 255 255
0 0 255 255
0 0 0 0
0 0 0 01
4 4
100 120 130 140
80 90 100 110
60 70 80 90
40 50 60 70
2
0 2
BRIGHTNESS 30
FLIP_V
0 1
THRESHOLD 1004 4
70 80 90 100
90 100 110 120
110 120 130 140
130 150 160 170
4 4
255 255 255 255
0 0 255 255
0 0 0 0
0 0 0 0