DIP+CV · Programming Exercise

EP03_03 — 🎭 Image Inversion (Photographic Negative)

3.14.3 EP03_03 🎭 Image Inversion (Photographic Negative)

In radiology, X-ray images are traditionally viewed as negatives: bones appear in black on a white background. The photographic negative operation is routinely applied in PACS (Picture Archiving and Communication Systems) to facilitate the detection of fractures and bone densities.

See Figure 3.28 for a simulation of this EP.

3.14.3.1 📋 Implementation Guidelines

  1. Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
  2. Data: Read the integer values of the original matrix.
  3. Mapping: For each pixel \(p\), compute the negative:

\[p' = 255 - p\]

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

3.14.3.2 📌 Computational Constraints

  • No clipping required: The result of \(255 - p\) with \(p \in [0, 255]\) is always \(\in [0, 255]\).
  • Integer type: The output must consist of integer values.
  • Logical equivalence: The operation is identical to the bitwise NOT (mm.bnot) on 8-bit images.

3.14.3.3 🧠 Theoretical Foundation

Original Pixel \(p\) Negative Pixel \(p'\) Observation
0 (black) 255 (white) Total inversion
128 (medium gray) 127 (medium gray) Central value
255 (white) 0 (black) Total inversion

3.14.3.4 📦 Input and Output Specification (VPL)

Input:

  • Line 1: Integer \(L\).
  • Line 2: Integer \(C\).
  • Following lines: Integer elements of the original matrix.

Output:

  • Negative matrix with \(L\) rows and \(C\) columns.

3.14.3.5 📌 Examples

Input Output Observation
1
4
0 128 200 255
255 127 55 0 Inversion of each pixel
2
2
10 20
30 40
245 235
225 215
Inverted 2x2 matrix
🎭 Simulator EP03_03: Photographic Negative (Inversion) p' = 255 − p

Observe the complementary intensity inversion: dark tones become light and light tones become dark by subtracting each pixel from the maximum value of 255.

Original Input (p)
Negative (p' = 255 − p)
 
Formula applied: p' = 255 − p
Figure 3.28: EP03_03 Simulator: Image Inversion — Photographic Negative (p’ = 255 − p)
%%writefile EP03_03.py
# Python code
Overwriting EP03_03.py
TestSuite("EP03_03.py").run()
✔️ EP03_03.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_03.cases

🔍 Testing Python: EP03_03.py
⚠️ EP03_03.py: Empty file (fewer than 3 lines). Tests skipped.