goconv2

module
v0.0.0-...-b3c1e68 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT

README

Goconv2 - Two-dimensional convolutions in Go

This implements various 2d convolutions in Go, useful for signal processing and computer vision.

Gonum's matrices are used as data types.

All implementations are tested against the output of the equivalent implementations in SciPy, assuming that those are probably correct. The documentation is also conveniently outsourced to SciPy, links are included in godoc.

There are different implementations of the same functions:

  • Naive Go - more or less copied 1:1 from the textbook. Those are very slow, because the Go compiler does not optimize a lot.
  • Slightly optimized Go - a little faster. Only two most useful variants (to the author) are implemented.
  • Cgo - much faster, even though they look like the naive implementations. The reason is that C compilers are much better at optimizing. Only two most useful variants (to the author) are implemented.
  • An implementation using FFTs. This is only worth it for large images/matrices. Only the most useful variant (to the author) is implemented.

To choose the right implementation for you use case, you can tweak the image sizes used in the benchmark in pkg/conv2/testutils.go, and then run make bench. In most of the case, the Cgo implementations seem to be the most useful ones.

For usage examples, see the tests in pkg/conv2.

TODOs

  • Tweak CPU optimizations (currently they are targeted to Raspberry Pis and seem to not always work).
  • Implement more optimized versions.
  • Optimize: do 2 FFTs in one.
  • Test panics.
  • Make it possible to configure what FFT is used.

Directories

Path Synopsis
internal
pkg/imutil
Package imutil is an internal package which contains various utilities for loading, storing, and generating image files.
Package imutil is an internal package which contains various utilities for loading, storing, and generating image files.
pkg/plot
Package plot in an internal package that plots.
Package plot in an internal package that plots.
pkg/testutil
Package testutil is an internal package which contains various utilities for loading and storing data.
Package testutil is an internal package which contains various utilities for loading and storing data.
pkg
conv2
Package conv2 contains various implementations of two-dimensional convolutions.
Package conv2 contains various implementations of two-dimensional convolutions.

Jump to

Keyboard shortcuts

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