This project implements an image processing program in C, capable of handling both grayscale (PGM) and color (PPM) images.
It was developed as part of an academic assignment in Imperative Programming (2024-2025), with the goal of understanding low-level image manipulation and transformation techniques using the C language.
The program reads, processes, and writes images using custom-built modules and supports various transformations such as color conversion, brightness adjustment, inversion, level quantization, and image resampling (nearest neighbor and bilinear interpolation).
- Implement basic image reading and writing for PPM and PGM formats.
- Understand and manipulate image structures, pixel data, and color channels.
- Apply a variety of transformations — e.g. brightness, inversion, quantization, blending, etc.
- Apply Look-Up Tables (LUTs) for pixel transformations.
- Implement arithmetic operations and resampling techniques on images.
- Provide a modular and maintainable codebase written entirely in C.
Both PPM (Portable Pixmap) and PGM (Portable Graymap) are simple image formats developed by Jef Poskanzer in 1988.
They are defined by a magic number — P6
for binary PPM and P5
for binary PGM — followed by image dimensions and pixel values ranging from 0 to 255.
- PGM (P5) → Grayscale images with one channel (intensity).
- PPM (P6) → Color images with three channels: Red, Green, and Blue.
File | Description |
---|---|
pictures.h / pictures.c | Defines and implements core image operations such as reading, writing, creating, copying, converting, and cleaning images. |
pixels.h / pixels.c | Manages pixel-level operations and defines symbolic color constants (RED, GREEN, BLUE) for RGB components. |
lut.h / lut.c | Defines the Look-Up Table (LUT) structure and functions to create, clean, and apply LUTs for pixel transformations. |
filename.h / filename.c | Provides functions to manipulate file paths and automatically generate output filenames based on operations. |
main.c | The main entry point that demonstrates all implemented functionalities (conversion, brightness, inversion, resampling, etc.). Each function block is commented, and you can activate one at a time by uncommenting it. |
Makefile | Automates compilation of all source files into an executable. |
To compile the project, simply use the provided Makefile:
make
This will generate an executable file named (for example) prog
or similar depending on your Makefile configuration.
Run the program by specifying the input image file(s):
./prog Lenna_color.ppm
OR
./prog Lenna_gray.pgm
Some functions require additional input images (e.g., mask or secondary image):
./prog Lenna_color.ppm Lenna_gray.pgm
Only one function block should be active in main.c
during execution — you can uncomment the function you want to test.
Example:
Input : Lenna_color.ppm
Output : Lenna_color_convert_gray.ppm
The following operations are implemented and demonstrated in main.c
:
- Read and Write Image
- Convert Gray ↔ Color
- Split RGB Channels
- Brighten Image
- Melt (pixel blending)
- Inverse (negative image)
- Normalize Dynamic Range
- Apply LUT Transformation
- Set Levels (quantization)
- Resample (nearest & bilinear) — resize image smaller or larger
- Arithmetic Operations — difference, product, mixture of images
- Wikipedia – Portable Pixmap
- Wikipedia – Image Scaling
- Chathura Gunasekera – Image Resampling Algorithms
Veasna RA
Imperative Programming Project – January 2025