Points: 50
The Jigsaw Puzzle
During a covert operation in Sherlock Holmes’ private archives, a crucial photographic record was sabotaged. The image was broken into nine equal tiles. All the nine photographic tiles survived. But before they could be secured, an unknown adversary tampered with them:
- Each plate was rotated by a distinct mechanical distortion.
- All nine tiles were then scrambled and reassembled into a misleading composite.
Holmes identified a subtle but decisive clue: the top-left pixel of every tile. This pixel is a compact encoding of the tile’s original position and orientation.
The Image:
a 300×300 image containing a 3×3 grid of 100×100 pixel tiles (9 shards total). Tiles are indexed 0–8 in row-major order (refer below for the numbering layout).
The Encoded Information
The top-left pixel (row=0, col=0) of each tile encodes two values in its BGR channels:
| Channel | Value to be extracted | What the value encodes |
|---|---|---|
| Red | Lower Nibble | Original tile index (0–8) |
| Green | Upper Nibble | Clockwise rotation that was applied to the original tile (0–3) |
Rotation codes:
- 0 → 0°
- 1 → 90° CW
- 2 → 180°
- 3 → 270° CW
Your Mission: Decode each tile’s embedding and report to Sherlock with the reassembled image.
Deliverables
- Your code (solution.cpp) - Complete source file.
- restored.png - Output image generated by running the code on 1_cvshred.png.