Pixel Budget
Implement 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.
Image Format
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.
Operations
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— Adddto 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 theh x wsub-image starting at rowr, columnc. All subsequent operations use this smaller image.ROTATE_90— Rotate the image 90° clockwise.THRESHOLD t— Set each pixel to255if it is≥ t, else0.
Input Format
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.
Output Format
For each script (in order), output the resulting image:
H W
<row 0>
...
<row H-1>
with a blank line between images.
Notes
- Clamping is applied after each operation individually, not once at the end.
ROTATE_90clockwise means rowr, columncmaps to rowc, column(H-1-r)in the new image (new dimensions areW x H).- Scripts are independent — each starts from the original image at
img_index, not from the result of a previous script. - Pixel values in output rows are space-separated.
Constraints
1 ≤ N ≤ 201 ≤ S ≤ 501 ≤ H, W ≤ 1281 ≤ K ≤ 20CROPis always given valid arguments:r + h ≤ Handc + w ≤ Wat the time of the crop.- No script produces an image smaller than
1 x 1.
Examples
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