DIP+CV Β· Programming Exercise

EP01_08 β€” 🎨 Intensity Range Remapping

1.18.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.18.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.18.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.18.11.3 πŸ“Œ Examples

Input Output Observation
2 4
128 60 -40
0 100 150 255
80 128 200 30
60 160 110 215
140 88 160 90
Pixels < 128 add 60. Pixels β‰₯ 128 subtract 40.
πŸŽ›οΈ Simulator EP01_08: Conditional Range Remapping p < T β†’ p + δ₁ | p β‰₯ T β†’ p + Ξ΄β‚‚

Adjust the separation threshold (T) and the brightness shifts (δ₁ and Ξ΄β‚‚) to apply differentiated intensity transformations in the dark and light regions of the image.

128
+60
-40
Original Input (p)
Transformed Result
Active rule: p < 128 β†’ p + (+60) Β |Β  p β‰₯ 128 β†’ p + (-40)
FigureΒ 1.18: EP01_08 Simulator: Conditional Range Remapping (Brightness and Contrast by Threshold)
# your solution
TestSuite("EP01_08.py").run()
βœ”οΈ EP01_08.cases already exists in casos/
πŸ“‹ 8 case(s) loaded from casos/EP01_08.cases
πŸ’₯ File EP01_08.py not found.