Adjust the separation threshold (T) and the brightness shifts (Ξ΄β and Ξ΄β) to apply differentiated intensity transformations in the dark and light regions of the image.
1.19.11 EP01_08 π¨ Intensity Range Remapping
In this activity, you must write a program that applies distinct linear transformations to different intensity regions of the image.
- Read two integers L and C, representing the matrix dimensions.
- Read the integers T (threshold), Ξ΄β (delta 1), and Ξ΄β (delta 2).
- Read the integer values of the matrix.
- For each pixel \(p\), apply the conditional remapping rule:
\[\text{result} = \begin{cases} p + \delta_1 & \text{if } p < T \\ p + \delta_2 & \text{if } p \ge T \end{cases}\]
- Print the resulting matrix with the new intensity values.
π Important:
- Ξ΄β is the offset applied to dark pixels (below the threshold).
- Ξ΄β is the offset applied to bright pixels (greater than or equal to the threshold).
- Test cases guarantee that the result will always be within the valid range of 0 to 255, so there is no need to handle saturation or rounding.
- The output must preserve the matrix structure (L rows and C columns).
1.19.11.1 π§ Conditional Pixel Transformation
In Digital Image Processing (DIP), we often need to handle regions independently. This technique allows, for example, brightening only the shadows of a photograph (increasing dark pixels) without blowing out the highlights of already bright areas, or vice versa.
| Intensity Range | Condition | Operation |
|---|---|---|
| Dark Pixels | \(p < T\) | \(p + \delta_1\) |
| Bright Pixels | \(p \ge T\) | \(p + \delta_2\) |
1.19.11.2 π Task (VPL specification)
Input:
The first line contains the integers L and C.
The second line contains the integers T, Ξ΄β, and Ξ΄β.
The following lines contain the matrix elements.
Output:
The transformed matrix with L rows and C columns, with space-separated values.
1.19.11.3 π Examples
| Input | Output | Observation |
|---|---|---|
2 4128 60 -400 100 150 25580 128 200 30 |
60 160 110 215140 88 160 90 |
Pixels < 128 add 60. Pixels β₯ 128 subtract 40. |
%%writefile EP01_08.cpp
// your solutionOverwriting EP01_08.cpp
TestSuite("EP01_08.cpp").run()βοΈ EP01_08.cases already exists in casos/
π 8 case(s) loaded from casos/EP01_08.cases
π Testing C++: EP01_08.cpp
β οΈ EP01_08.cpp: Empty file (fewer than 3 lines). Tests skipped.