afmm

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 6 Imported by: 0

README

afmm

This package implements an augmented fast marching method algorithm for skeletonization of binary masks in Go, as provided by Alexandru C. Telea and Jarke J. van Wijk in Telea, A. C., & Wijk, van, J. J. (2002). An augmented Fast Marching Method for computing skeletons and centerlines. In Proceedings of the symposium on Data Visualization 2002 (VisSym'02, Barcelona, May 27-29, 2002) (pp. 251-259). Eurographics Association. Now updated to AFMM star in Reniers, Dennie & Telea, Alexandru. (2007). Tolerance-Based Feature Transforms. 10.1007/978-3-540-75274-5_12.

There are three main routines exported by this package, the simplest of which is a distance transform of the binary mask using the fast marching method (FMM). Then we augment this algorithm to take into account the source pixel at the boundary with (AFMM). This function returns the discontinuity magnitude field of these sources, implying a centerline. Finally, we have the all-in-one function Skeletonize which takes in a picture and a threshold t. It performs AFMM and then thresholds the discontinuity field to extract a new grayscale image.Image containing the skeleton and ignoring boundary effects smaller than t pixels.

Usage

Say we have an image in the PNG format which we read into an image.Image variable as follows

  // "os" and "image" imported

  reader, err := os.Open("./example.png")
  if err != nil {
      log.Fatal(err)
  }
  
  img, _, err := image.Decode(reader)
  if err != nil {
    log.Fatal(err)
  }

With example.png being the image

example

The result of afmm.FMM(img) is the distance transform in a contiguous array. After reshaping it into the shape of the image we get

distance transform.

The output of afmm.AFMM(img) on an image is a slice of floats which is higher at the centerlines, also in a contiguous fashion and requires the same reshaping as afmm.FMM. For the above example, we get

magnitude of discontinuities in boundary source pixels.

Finally, the output of afmm.Skeletonize(img, t) is an image.Image where we threshold the above data by t. Different values of t yield different skeletons. For instance, for t=20, 100 and 250:

Documentation

Overview

Package afmm contains an implementation of the augmented fast marching method for skeletons and centerlines of binary images

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AFMM

func AFMM(img *image.Image) ([]float64, []float64)

AFMM is a modification of FMM where, alongside distance, we propagate the pixel this distance stems from. By probing discontinuities in this new field, we are able to find the centerline/skeleton. It returns the discontinuity magnitude from which small boundary defects can be thresholded. It also returns the distance transform as FMM

func FMM

func FMM(img *image.Image) []float64

FMM computes the distance transform of the binary mask provided as argument, i.e., computes how far a non-background pixel (white) is from a background pixel (black)

func Skeletonize

func Skeletonize(img *image.Image, t float64) image.Image

Skeletonize takes an image.Image representing a binary mask and a threshold value, t, and returns an image.Image of the centerline or skeleton of this mask. Black pixels represent the background, and white pixels represent the object being skeletonized. Boundary defects less than t pixels are ignored. Improve the output by tuning t to the image.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL