In this activity, you must write a program that computes the negative of a digital image.
Read two integers L and C, representing the number of rows and columns.
Read the integer values that make up the image matrix.
For each pixel, apply the inversion transformation:
\[pixel_{negative} = 255 - pixel_{original}\]
Print the resulting matrix, preserving the original format (L rows and C columns).
📌 Important:
The values in each row of the output must be separated by a single space.
The output must contain only the numbers of the resulting matrix.
See an interactive simulator for this problem at Figure 1.15 (real-time comparison between the original matrix and its negative).
1.18.8.1 🧠 Why Does This Matter? – Intensity Inversion
The negative is a basic linear transformation that inverts the brightness scale. It is an essential tool for the human eye to identify light details that are “hidden” in darker backgrounds, being widely used in:
Application
Utility
Medical Imaging
Enhances the visualization of anomalies in dense tissues (e.g., X-rays).
Astronomy
Highlights faint galaxies and nebulae against the void of space.
Digital Arts
Aesthetic effects and preparation of selection masks.
1.18.8.2 📋 Task (Specification for VPL)
Input:
The first line contains the integer L.
The second line contains the integer C.
The following lines contain the elements of the matrix.
Output:
The inverted matrix with L rows and C columns.
1.18.8.3 📌 Examples
Input
Output
Observation
2
3
0 128 255
50 100 255
255 127 0
205 155 55
Where it was 0 (black) becomes 255 (white)
🌓 Simulator EP01_05: Image Negative Transformationp' = 255 - p
Click on the pixels of the matrix Original (p) to change their grayscale levels (step of +51) and observe the effect of complementary inversion on the matrix Negative (255 - p).
ORIGINAL (p)
NEGATIVE (255 - p)
💡The negative transformation maps dark tones (close to 0) to light tones (close to 255) and vice versa, being useful for highlighting dark details on light backgrounds.