DIP+CV · Programming Exercise

EP02_01 — ☀️ Brightness and Contrast Adjustment

2.12.1 EP02_01 ☀️ Brightness and Contrast Adjustment

In this activity, the goal is to implement a point operator for linear intensity transformation, applying dynamic brightness and contrast adjustment to a digital image.

2.12.1.1 📋 Implementation Guidelines

The algorithm should follow the execution flow below:

  1. Dimensions: Read the integers \(L\) (rows) and \(C\) (columns) of the matrix.
  2. Parameters: Read the real value \(\alpha\) (contrast factor) and the integer \(\beta\) (brightness factor).
  3. Data: Read the integer values of the original matrix.
  4. Mapping: For each pixel \(p\), compute the new value \(p'\) using the equation:

\[p' = \text{clip}(\text{round}(\alpha \cdot p + \beta))\]

  1. Output: Display the resulting matrix with dimensions \(L \times C\).

2.12.1.2 📌 Computational Constraints

  • Rounding (Round): Mathematical rounding to the nearest integer is applied before type conversion.
  • Clipping (Saturation): Values must be confined to the range \([0, 255]\) to preserve the 8-bit standard:

\[\text{clip}(x) = \max(0, \min(255, x))\]

  • Simulation: The effect of the parameters \(\alpha\) and \(\beta\) on histogram correction can be observed in Figure 2.12.

2.12.1.3 🧠 Theoretical Background

These changes modify the image histogram to adjust the illumination profile and tonal distinction.

Parameter Function Visual Impact
\(\alpha\) (Alpha) Scalar Modulates Contrast. If \(\alpha > 1\), it expands the histogram; if \(0 \le \alpha < 1\), it compresses it.
\(\beta\) (Beta) Additive Modulates Brightness. If positive, it shifts the histogram to the right; if negative, to the left.
\(\text{clip}\) Limiter Restricts the dynamic range, preventing underflow and overflow errors.

2.12.1.4 📦 Input and Output Specification (VPL)

Input:

  • Line 1: Integer \(L\).
  • Line 2: Integer \(C\).
  • Line 3: Values of alpha (\(\alpha\)) and beta (\(\beta\)).
  • Following lines: Numeric elements of the original matrix.

Output:

  • Transformed matrix structured into \(L\) rows and \(C\) columns.

2.12.1.5 📌 Examples

The following table presents a practical example of the algorithm’s expected behavior, highlighting the action of the rounding and clipping operators.

Input Output Observation
1
4
1.5 -30
0 100 180 255
0 120 240 255 Note the clipping effect on the last pixel

Running the Tests

To evaluate the tests, run TestSuite("EP02_01.extensão").run() in a new cell, replacing the extension with that of the language used (.py, .java, .c, .cpp, .js, or .r). The system downloads the test cases from GitHub, runs the program, and calculates the grade automatically.

☀️ Simulator EP02_01: Linear Brightness and Contrast Adjustment p' = clip(α·p + β)

Adjust the contrast (α) and brightness (β) parameters to apply the point intensity transformation and observe the saturation clipping in the range [0, 255].

1.0
0
Original Input (p)
Transformed Result (p')
Formula applied: clip( round(1.0 · p + (0)) )
Figure 2.12: Simulator EP02_01: Linear Brightness and Contrast Adjustment (p’ = αp + β)