A C implementation of the Marching Squares algorithm for generating contours from PPM (P3) images. This program processes images to detect and draw contours based on luminance thresholds, providing both grid analysis and visual output.
- Read PPM Images: Supports reading P3 format images with proper validation.
- Grid Generation: Computes a binary grid based on luminance thresholds.
- Contour Lookup Tables: Utilizes 16 predefined contour patterns for drawing.
- Image Resizing: Upscales images by a factor of 4x.
- Marching Squares Application: Applies the algorithm to generate contour lines.
- Command-Line Interface: Interactive commands for processing images step-by-step.
- C Compiler: GCC or another C compiler.
- Standard Libraries: Uses
<stdio.h>,<stdlib.h>, and<string.h>.
-
Clone the repository:
git clone https://github.com/mihai1923/marching-squares cd marching-squares -
Compile the code:
gcc marching-squares.c -o marching-squares
Run the program and enter commands interactively:
./marching_squres| Command | Description |
|---|---|
READ |
Load a P3 PPM image. Prompts for width, height, and pixel data. |
WRITE |
Output the current image in P3 format. |
GRID |
Compute and display the binary grid based on luminance (threshold: α=200). |
INIT_CONTOUR |
Print all 16 contour patterns (lookup tables). |
RESIZE |
Upscale the image by 4×. |
MARCH |
Apply the Marching Squares algorithm to draw contours. |
EXIT |
Exit the program. |
-
Load an Image:
READ
-
Generate Grid:
GRID
-
Apply Contours:
MARCH
-
Save/View Result:
WRITE
-
Exit:
EXIT