autostereo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 6 Imported by: 0

README

autostereo

Create 3D optical illusions from 2D images.

Background

An autostereogram is a two-dimensional (2D) image that can create the optical illusion of a three-dimensional (3D) scene.

https://en.wikipedia.org/wiki/Autostereogram

If you have ever seen a Magic Eye® illustration, you have seen an autostereogram.

The algorithm used by this package is adapted from a paper entitled Displaying 3D Images: Algorithms for Single Image Random Dot Stereograpms, by Harold W. Thimbleby, Ian H. Witten, and Stuart Inglis.

http://harold.thimbleby.net/sirds/ieee3d.pdf

Documentation

GoDoc API documentation: https://pkg.go.dev/git.sr.ht/~jgoulder/autostereo

Autostereo Package

Package autostereo provides routines for creating 3D optical illusions from 2D images. It is used by both the autostereo and autostereo-gui commands.

Installation
go get git.sr.ht/~jgoulder/autostereo@latest

Autostereo Command

Command autostereo is a command-line application for creating 3D optical illusions from 2D images.

Installation
go install git.sr.ht/~jgoulder/autostereo/cmd/autostereo@latest
Usage

The following example shows the results of creating an autostereogram from a depth map using the autostereo command.

The depth map is contained in gopher.depth.png and the resulting autostereogram is saved to gohper.asg.png.

You can see the command and the input and output images below.

autostereo -d ./gopher.depth.png -o ./gopher.asg.png

Depth map intput image based on a 3D model of the Go Gopher mascot:

Gopher Depth Map

Autostereogram output image:

Gohper Autostereogram

Autostereo-gui Command

Command autostereo-gui is a desktop application for creating and viewing 3D optical illusions from 2D images.

Requirements
Arch Linux
sudo pacman -S base-devel
sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
Fedora
sudo dnf group install "C Development Tools and Libraries"
sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
Ubuntu
sudo apt install build-essential
sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev
macOS

On macOS you need Xcode or Command Line Tools for Xcode.

Windows

On Windows you need C compiler, like Mingw-w64 or TDM-GCC. You can also build binary in MSYS2 shell.

Installation
go install git.sr.ht/~jgoulder/autostereo/cmd/autostereo-gui@latest
Usage

The following example shows the results of running the autostereogram-gui command.

The depth map is contained in gopher.depth.png.

autostereo-gui -d ./gopher.depth.png

Pressing the TAB key will cycle through the predefined color palettes.

Autostereo-gui window:

Autostereo-gui Window

Documentation

Overview

Package autostereo provides routines for creating 3D optical illusions from 2D images.

Index

Constants

View Source
const DepthOfFieldMax = 1.0

DeptOfFieldMax is the maximum allowable value for the dept of field, as a fraction of viewing distance.

View Source
const DepthOfFieldMin = 0.0

DeptOfFieldMin is the minimum allowable value for the dept of field, as a fraction of viewing distance.

View Source
const EyeSeparationMax = 125.0

EyeSeparationMax is the maximum allowable value for the eye separation in millimeters.

View Source
const EyeSeparationMin = 25.0

EyeSeparationMin is the minium allowable value for the eye separation in millimeters.

Variables

View Source
var ErrInvalidDepthMap = errors.New("invalid depth map image")

ErrInvalidDepthMap indicates that a given depth map image is not suitable.

A depth map image must not be nil, must have a size of at lease 1 x 1, and must have a size that is bounded.

View Source
var ErrInvalidPattern = errors.New("invalid pattern image")

ErrInvalidPattern indicates that a given pattern image is not suitable.

A pattern image must have a size of at least 1x1 pixels, and must have a size that is bounded.

View Source
var PaletteBlackAndWhite = []color.Color{
	color.Black,
	color.White,
}

PaletteBlackAndWhite contains a color palette with just two colors, black and white.

View Source
var PaletteCyberPunk = []color.Color{
	color.RGBA{R: 10, G: 23, B: 45, A: 255},
	color.RGBA{R: 240, G: 0, B: 219, A: 255},
	color.RGBA{R: 98, G: 24, B: 130, A: 255},
	color.RGBA{R: 19, G: 61, B: 201, A: 255},
	color.RGBA{R: 11, G: 196, B: 207, A: 255},
}

PaletteCyberPunk contains a cool looking Cyber Punk palette.

View Source
var PaletteGrayScale = []color.Color{
	color.Black,
	color.RGBA{R: 32, G: 32, B: 32, A: 255},
	color.RGBA{R: 64, G: 64, B: 64, A: 255},
	color.RGBA{R: 96, G: 96, B: 96, A: 255},
	color.RGBA{R: 128, G: 128, B: 128, A: 255},
	color.RGBA{R: 160, G: 160, B: 160, A: 255},
	color.RGBA{R: 192, G: 192, B: 192, A: 255},
	color.RGBA{R: 255, G: 255, B: 255, A: 255},
}

PaletteGrayScale contains an eight-color gray-scale palette.

Palettes contains a slice of all the pre-defined color palettes.

Functions

func Create

func Create(depthMap image.Image, pattern image.Image, config *Config) (image.Image, error)

Create returns an image containing an autostereogram created using the given depth map and background pattern. If nil is given for the pattern, a default pattern is generated.

func RandomPattern

func RandomPattern(r image.Rectangle) draw.Image

RandomPattern returns a pattern with the bounds of the given image.Rectangle and random black and white dots.

func RandomPatternPalette

func RandomPatternPalette(r image.Rectangle, palette color.Palette) draw.Image

RandomPatternPalette returns a pattern with the bounds of the given image.Rectangle and random dots of color from the given palette.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config contains the configuration paramaters that are used when creating an autostereogram.

func (*Config) DepthOfField

func (c *Config) DepthOfField() float32

SetDepthOfField returns the configured value for the depth of field, as a fraction of the viewing distance.

func (*Config) EyeSepartation

func (c *Config) EyeSepartation() float32

EySeparation returns the configured value for the eye separation in milimeters.

func (*Config) ScreenDPI

func (c *Config) ScreenDPI() float32

ScreenDPI returns the configured value for the screen DPI in dots per inch.

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets all the configuration paramaters to their default vaules.

func (*Config) SetDepthOfField

func (c *Config) SetDepthOfField(dof float32)

SetDepthOfField sets the value for the depth of field, as a fraction of the viewing distance.

func (*Config) SetEyeSeparation

func (c *Config) SetEyeSeparation(milimeters float32)

SetEyeSeparation sets the value for the eye separation in milimeters.

func (*Config) SetSceenDPI

func (c *Config) SetSceenDPI(dpi float32)

SetScreenDPI sets the value of the screen DPI in dots per inch.

Directories

Path Synopsis
cmd
autostereo
Autostereo is a command-line application for creating 3D optical illusions from 2D images.
Autostereo is a command-line application for creating 3D optical illusions from 2D images.
autostereo-gui
Autostereo-gui is a desktop application for creating and viewing 3D optical illusions from 2D images.
Autostereo-gui is a desktop application for creating and viewing 3D optical illusions from 2D images.

Jump to

Keyboard shortcuts

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