Skip to content

mihai1923/marching-squares

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Marching Squares Contour Generator

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.

Features

  • 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.

Prerequisites

  • C Compiler: GCC or another C compiler.
  • Standard Libraries: Uses <stdio.h>, <stdlib.h>, and <string.h>.

Installation

  1. Clone the repository:

    git clone https://github.com/mihai1923/marching-squares
    cd marching-squares
  2. Compile the code:

    gcc marching-squares.c -o marching-squares

Usage

Run the program and enter commands interactively:

./marching_squres

Commands

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.

Example Workflow

  1. Load an Image:

    READ
    
  2. Generate Grid:

    GRID
  3. Apply Contours:

    MARCH
  4. Save/View Result:

    WRITE
  5. Exit:

    EXIT

About

A C implementation of the Marching Squares algorithm to generate and visualize contours from P3 PPM images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors