EP03_01 ➕ Saturated Addition of a Constant
In video surveillance systems, cameras in environments with variable lighting produce underexposed images. Adjusting brightness by saturated addition of a constant is the simplest operation for immediate correction, being applied in real time on embedded camera chips and in preprocessing pipelines of mobile robots.
See Figure 3.26 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
Constant: Read the integer \(k\) (value to be added).
Data: Read the integer values of the original matrix row by row.
Mapping: For each pixel \(p\) , compute the new value using the equation:
\[p' = \text{clip}(p + k)\]
Output: Display the resulting matrix with dimensions \(L \times C\) .
📌 Computational Constraints
Saturation (Clipping ): Values must be confined to the interval \([0, 255]\) : \[\text{clip}(x) = \max(0, \min(255, x))\]
Type: The final result must be an integer (no decimal places).
\(k\) can be negative: negative values darken the image; positive values lighten it.
🧠 Theoretical Background
\(k > 0\)
Integer
Lightens the image; pixels near 255 saturate to white
\(k < 0\)
Integer
Darkens the image; pixels near 0 saturate to black
\(k = 0\)
Integer
Image unchanged
📌 Examples
2
3
50
0 100 200
210 240 255
50 150 250
255 255 255
Saturation at 255 for high pixels
1
4
-30
0 20 200 255
0 0 170 225
Saturation at 0 for low pixels
Figure 3.26: Simulador EP03_01: Saturated Addition of Constant (p’ = clip(p + k))
%% writefile EP03_01.cpp
// your solution
TestSuite("EP03_01.cpp" ).run()
✔️ EP03_01.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_01.cases
🔍 Testing C++: EP03_01.cpp
⚠️ EP03_01.cpp: Empty file (fewer than 3 lines). Tests skipped.