Theory
A digital image is a function f(x, y) sampled on a rectangular grid. Each sample is a pixel, and its value records how much light reached that point. An 8-bit grayscale image stores one value per pixel from 0 (black) to 255 (white). A color image stores three values per pixel, one per channel, so its shape is height × width × channels and an uncompressed 8-bit color image occupies H × W × 3 bytes.
Libraries disagree on channel order. Browsers and most image formats use RGB, while OpenCV loads images as BGR. Mixing the two swaps red and blue, which is the most common bug in a first computer vision program.
Color spaces
RGB is additive and matches how screens emit light, but it mixes color and brightness in every channel. Other spaces separate them:
- Grayscale keeps only luminance, Y = 0.299 R + 0.587 G + 0.114 B (ITU-R BT.601). Green weighs most because the eye is most sensitive to it.
- HSV splits hue, saturation and value, which makes color-based selection easy.
- CIE LAB is designed so equal distances look like equal color differences.
- YCrCb separates luma from two chroma channels and is the basis of JPEG compression.
Geometric transformations
Resizing maps output pixels back to input coordinates and interpolates: nearest neighbour copies the closest pixel, bilinear blends the four nearest, bicubic fits a smooth surface over sixteen. Rotation, translation and scaling are affine maps that can be written as one 2×3 matrix:
Cropping is array slicing, and flipping reverses the order of rows or columns.
Intensity transformations
Point operations change each pixel independently:
- Contrast and brightness: g(x, y) = α f(x, y) + β
- Negative: s = 255 − r
- Gamma correction: s = 255 (r / 255)^γ, which brightens shadows when γ < 1 and darkens them when γ > 1.
Workbench
Load a sample, an upload or the webcam, then read pixel values by hovering the image.
Input
Input preview
Parameters
Readout
- n/a
- n/a
Export
Procedure
- Open the workbench and load the Street at dusk sample. Record its width, height and number of channels from the readout.
- Hover several regions (sky, road, the red car) and write down their RGB values. Explain how each value relates to the color you see.
- Convert the image to grayscale, HSV, LAB and YCrCb. Display each channel separately and describe what it isolates.
- Resize the image to half and double size with nearest, bilinear and bicubic interpolation. Compare the edges of the car.
- Rotate the image by 30° and 90°, flip it horizontally and vertically, and crop the region around the person.
- Apply brightness and contrast changes, the negative, and gamma values of 0.5 and 2.0. Note the effect on dark and bright areas.
- Repeat steps 2 to 6 on your own photograph using Upload, then on a live webcam frame.
- Save a figure for each step with Save figure for report.
Results and Discussion
To be completed
Add your figures and observations here once the activity is done: pixel values you recorded, how each color space separated the scene, which interpolation looked best when enlarging, and how gamma changed the shadows.
Conclusion
To be completed
Summarize what you learned about image representation, color spaces and basic transformations, in your own words.