DIP+CV · Programming Exercise

EP01_04 — 🖼️ Reading and Information from a Matrix Image

1.19.7 EP01_04 🖼️ Reading and Information from a Matrix Image

In this activity, you must write a program that processes a digital image represented as a matrix of grayscale pixels.

  • Read two integers L and C, representing the number of rows and columns.
  • Read the L * C integer values that compose the image matrix (each value between 0 and 255).
  • Calculate and print the following information:
  1. The number of rows.
  2. The number of columns.
  3. The value of the largest pixel (Maximum).
  4. The value of the smallest pixel (Minimum).
  5. The arithmetic Mean of all pixels.

📌 Important:

  • The output must follow exactly the labeled format (e.g., Linhas: X).
  • The mean value must be formatted with two decimal places.
  • See an interactive simulator for this question at Figure 1.14 (interactive grid for visualizing intensities and real-time calculations).

1.19.7.1 🧠 Why Does This Matter? – The Image as Data

Every digital image is, at its core, a data structure. In 8-bit grayscale, each pixel is a scalar value. Extracting basic statistics is the first step toward:

Operation Practical Utility
Maximum/Minimum Identifying whether the image is “washed out” (low contrast) or saturated.
Mean Calculating the overall brightness of the scene for exposure adjustments.
Normalization Rescaling values to ranges such as \([0, 1]\) in neural networks.

1.19.7.2 📋 Task (VPL specification)

Input:

The first line contains the integer L (rows).

The second line contains the integer C (columns).

The following lines contain the elements of the matrix.

Output:

Five lines formatted according to the example:

Linhas: L

Colunas: C

Max: V

Min: V

Media: V.VV

1.19.7.3 📌 Examples

Input Output Observation
2
3
0 128 255
50 100 200
Linhas: 2
Colunas: 3
Max: 255
Min: 0
Media: 122.17
Small high-contrast image
📊 Simulator EP01_04: Local Pixel Statistics 5x5 Matrix

Click on any pixel of the matrix to increment its gray level (step of +51) or use the predefined actions below to observe the limits and the global average.

Global Mean (µ)
0.00
Maximum Value
0
Minimum Value
0
Figure 1.14: EP01_04 Simulator: Pixel Statistics in Discrete 5x5 Matrix
%%writefile EP01_04.cpp
// your solution
Overwriting EP01_04.cpp
TestSuite("EP01_04.cpp").run()
✔️ EP01_04.cases already exists in casos/
📋 5 case(s) loaded from casos/EP01_04.cases

🔍 Testing C++: EP01_04.cpp
⚠️ EP01_04.cpp: Empty file (fewer than 3 lines). Tests skipped.