DIP+CV · Programming Exercise

EP01_09 — 🏁 Checkerboard Pattern: Chess Matrix

1.18.12 EP01_09 🏁 Checkerboard Pattern: Chess Matrix

In this activity, you must write a program that generates a synthetic image in the pattern of a chessboard.

  • Read two integers L (rows) and C (columns).
  • Generate a matrix where the values alternate between 0 (black) and 1 (white).
  • The filling logic must follow the parity rule:
  • The element at position \((0,0)\) is always 0.
  • A pixel at position \((i, j)\) will be 1 if the sum of the indices \((i + j)\) is odd.
  • A pixel at position \((i, j)\) will be 0 if the sum of the indices \((i + j)\) is even.

📌 Important:

  • The colors must alternate correctly both horizontally and vertically.
  • The output must be the matrix printed line by line, with the elements separated by a space.
  • See an interactive simulator for this problem at Figure 1.19 (adjust the dimensions to visualize the construction of the grid and the corresponding textual output).

1.18.12.1 🧠 Synthetic Patterns

Creating geometric patterns is a fundamental exercise for mastering index logic in matrices. In Digital Image Processing, the checkerboard pattern is not merely aesthetic; it is widely used for:

Application Utility
Camera Calibration Estimating intrinsic and extrinsic lens parameters.
Distortion Correction Identifying and correcting the “barrel” or “pincushion” effect in wide-angle lenses.
3D Mapping Projecting known patterns to reconstruct surfaces in structured light systems.

1.18.12.2 📋 Task (specification for VPL)

Input:

A line containing the integer L (rows).

A line containing the integer C (columns).

Output:

The checkerboard matrix with L rows and C columns, printed with spaces between the elements.

1.18.12.3 📌 Examples

Input Output Observation
3
4
0 1 0 1
1 0 1 0
0 1 0 1
Note that each row starts with the inverse of the previous one
🏁 Simulator EP01_09: Checkerboard Matrix Generator (i + j) % 2

Change the number of rows (L) and columns (C) to observe how the parity alternation of grid coordinates builds the binary checkerboard matrix.

×
GRAPHIC GRID
EXPECTED OUTPUT (VALUES)
Figure 1.19: EP01_09 Simulator: Checkerboard Pattern Generator (Parity Logic (i + j) % 2)
# your solution
TestSuite("EP01_09.py").run()
✔️ EP01_09.cases already exists in casos/
📋 7 case(s) loaded from casos/EP01_09.cases
💥 File EP01_09.py not found.