Git Product home page Git Product logo

marching-squares's Introduction

Marching Squares

Description

This C projects presents a parallelized implementation of the Marching Squares algorithm, applied specifically to topographic maps, using Pthreads. This method efficiently divides the workload among multiple threads to generate topographic map contours from an input image.

SAMPLE_GRID GRID_THRESHOLD_RESULT

Algorithm Steps

Initialization and Rescaling

Initially, the input image is optionally rescaled to a predefined dimension (2048x2048 pixels in this case) for uniformity and to facilitate a more manageable processing scale. This is particularly useful for large images and ensures that the algorithm performs optimally across different image sizes.

OPTIONAL_RESCALED

Grid Sampling

The image is divided into a grid of squares. Each grid point's value is determined based on a sigma (ฯƒ) threshold, which helps in identifying areas of interest by comparing the average color intensity of pixels within a grid cell against ฯƒ. This step effectively converts the image into a binary grid representation where each edge is marked as 0 or 1.

SAMPLE_GRID GRID_THRESHOLD_RESULT

Contour Mapping

The algorithm uses a predefined contour map list, which is a collection of small images corresponding to the 16 possible binary codes generated by moving circularly in a clockwise direction from the top-left corner of a square grid cell. These binary codes reflect the state of the 4 edges of a square, with each edge being part of a contour (1) or not (0). The circular motion ensures consistent binary code reading for all cells, contributing to the correct assembly of the entire contour map.

GRID_CONTOUR_VALUES CONTOURS

Marching Cells

For each cell in the binary grid, the algorithm examines the corners to identify one of the 16 possible patterns. Each pattern corresponds to a specific contour configuration. By applying this process across the grid, the algorithm delineates contours within the image.

FINAL_RESULT

Workload Distribution

  • Rescaling: each thread works on a different part of the image, using bicubic interpolation to maintain the same quality like the original image.
  • Sampling Grid: each thread computes the binary value for the corners of its assigned squares, based on a sigma threshold; parallel processing of this step means multiple grid squares are evaluated simultaneously.
  • Contour Mapping: lookup table with 16 possible patterns is used, corresponding to the 16 possible states of a 2x2 cell in the grid; threads compute the contour map and retrieve the corresponding contour image, which is then drawn onto the output image.
  • Marching Squares: once threads have the appropriate contour segment images, they 'march' through the grid, cell by cell, in a linear fashion to draw continuous contour lines.

marching-squares's People

Contributors

justin-marian avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.