moreland

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package moreland provides color maps for pseudocoloring scalar fields. The color maps are described at http://www.kennethmoreland.com/color-advice/ and in the following publications:

"Why We Use Bad Color Maps and What You Can Do About It." Kenneth Moreland. In Proceedings of Human Vision and Electronic Imaging (HVEI), 2016. (To appear)

"Diverging Color Maps for Scientific Visualization." Kenneth Moreland. In Proceedings of the 5th International Symposium on Visual Computing, December 2009. DOI 10.1007/978-3-642-10520-3_9.

Example

This Example gives examples of plots using the palettes in this package. The output can be found at https://github.com/gonum/plot/blob/master/palette/moreland/testdata/moreland_golden.png.

package main

import (
	"log"
	"math"
	"os"

	"github.com/elamre/plot"
	"github.com/elamre/plot/palette"
	"github.com/elamre/plot/palette/moreland"
	"github.com/elamre/plot/plotter"
	"github.com/elamre/plot/vg"
	"github.com/elamre/plot/vg/draw"
	"github.com/elamre/plot/vg/vgimg"
	"gonum.org/v1/gonum/mat"
)

type offsetUnitGrid struct {
	XOffset, YOffset float64

	Data *mat.Dense
}

func (g offsetUnitGrid) Dims() (c, r int)   { r, c = g.Data.Dims(); return c, r }
func (g offsetUnitGrid) Z(c, r int) float64 { return g.Data.At(r, c) }
func (g offsetUnitGrid) X(c int) float64 {
	_, n := g.Data.Dims()
	if c < 0 || n <= c {
		panic("index out of range")
	}
	return float64(c) + g.XOffset
}
func (g offsetUnitGrid) Y(r int) float64 {
	m, _ := g.Data.Dims()
	if r < 0 || m <= r {
		panic("index out of range")
	}
	return float64(r) + g.YOffset
}

func main() {
	m := offsetUnitGrid{
		XOffset: -50,
		YOffset: -50,
		Data:    mat.NewDense(100, 100, nil),
	}
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			x := float64(i-50) / 10
			y := float64(j-50) / 10
			v := math.Sin(x*x+y*y) / (x*x + y*y)
			m.Data.Set(i, j, v)
		}
	}

	const (
		rows = 3
		cols = 3
	)
	c := vgimg.New(vg.Points(800), vg.Points(800))
	dc := draw.New(c)
	tiles := draw.Tiles{
		Rows: rows,
		Cols: cols,
	}
	type paletteHolder struct {
		name string
		cmap palette.Palette
	}
	palettes := []paletteHolder{
		{
			name: "SmoothBlueRed",
			cmap: moreland.SmoothBlueRed().Palette(255),
		},
		{
			name: "SmoothBlueTan",
			cmap: moreland.SmoothBlueTan().Palette(255),
		},
		{
			name: "SmoothGreenPurple",
			cmap: moreland.SmoothGreenPurple().Palette(255),
		},
		{
			name: "SmoothGreenRed",
			cmap: moreland.SmoothGreenRed().Palette(255),
		},
		{
			name: "SmoothPurpleOrange",
			cmap: moreland.SmoothPurpleOrange().Palette(255),
		},
		{
			name: "BlackBody",
			cmap: moreland.BlackBody().Palette(255),
		},
		{
			name: "ExtendedBlackBody",
			cmap: moreland.ExtendedBlackBody().Palette(255),
		},
		{
			name: "Kindlmann",
			cmap: moreland.Kindlmann().Palette(255),
		},
		{
			name: "ExtendedKindlmann",
			cmap: moreland.ExtendedKindlmann().Palette(255),
		},
	}

	for i, plte := range palettes {

		h := plotter.NewHeatMap(m, plte.cmap)

		p, err := plot.New()
		if err != nil {
			log.Panic(err)
		}
		p.Title.Text = plte.name

		p.Add(h)

		p.X.Padding = 0
		p.Y.Padding = 0
		p.Draw(tiles.At(dc, i%cols, i/cols))
	}

	pngimg := vgimg.PngCanvas{Canvas: c}
	f, err := os.Create("testdata/moreland.png")
	if err != nil {
		log.Panic(err)
	}
	if _, err = pngimg.WriteTo(f); err != nil {
		log.Panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlackBody

func BlackBody() palette.ColorMap

BlackBody is a Luminance-class ColorMap based on the colors of black body radiation. Although the colors are inspired by the wavelengths of light from black body radiation, the actual colors used are designed to be perceptually uniform. Colors of the desired brightness and hue are chosen, and then the colors are adjusted such that the luminance is perceptually linear (according to the CIE LAB color space).

func ExtendedBlackBody

func ExtendedBlackBody() palette.ColorMap

ExtendedBlackBody is a Luminance-class ColorMap based on the colors of black body radiation with some blue and purple hues thrown in at the lower end to add some "color." The color map is similar to the default colors used in gnuplot. Colors of the desired brightness and hue are chosen, and then the colors are adjusted such that the luminance is perceptually linear (according to the CIE LAB color space).

func ExtendedKindlmann

func ExtendedKindlmann() palette.ColorMap

ExtendedKindlmann is a Luminance-class ColorMap uses the colors from Kindlmann but also adds more hues by doing a more than 360 degree loop around the hues. This works because the endpoints have low saturation and very different brightness.

func Kindlmann

func Kindlmann() palette.ColorMap

Kindlmann is a Luminance-class ColorMap that uses the colors first proposed in a paper by Kindlmann, Reinhard, and Creem. The map is basically the rainbow color map with the luminance adjusted such that it monotonically changes, making it much more perceptually viable.

Citation: Gordon Kindlmann, Erik Reinhard, and Sarah Creem. 2002. Face-based luminance matching for perceptual colormap generation. In Proceedings of the conference on Visualization '02 (VIS '02). IEEE Computer Society, Washington, DC, USA, 299-306.

func NewLuminance

func NewLuminance(controls []color.Color) (palette.ColorMap, error)

NewLuminance creates a new Luminance ColorMap from the given controlColors. luminance is a color palette that interpolates between control colors in a way that ensures a linear relationship between the luminance of a color and the value it represents. If the luminance of the controls is not monotonically increasing, an error will be returned.

func NewSmoothDiverging

func NewSmoothDiverging(start, end color.Color, convergeM float64) palette.DivergingColorMap

NewSmoothDiverging creates a new smooth diverging ColorMap as described in "Diverging Color Maps for Scientific Visualization." by Kenneth Moreland, in Proceedings of the 5th International Symposium on Visual Computing, December 2009. DOI 10.1007/978-3-642-10520-3_9.

start and end are the start- and end-point colors and convergeM is the magnitude of the convergence point in magnitude-saturation-hue (MSH) color space. Note that convergeM specifies the color of the convergence point; it does not specify the location of the convergence point.

func SmoothBlueRed

func SmoothBlueRed() palette.DivergingColorMap

SmoothBlueRed is a SmoothDiverging-class ColorMap ranging from blue to red.

func SmoothBlueTan

func SmoothBlueTan() palette.DivergingColorMap

SmoothBlueTan is a SmoothDiverging-class ColorMap ranging from blue to tan.

func SmoothGreenPurple

func SmoothGreenPurple() palette.DivergingColorMap

SmoothGreenPurple is a SmoothDiverging-class ColorMap ranging from green to purple.

func SmoothGreenRed

func SmoothGreenRed() palette.DivergingColorMap

SmoothGreenRed is a SmoothDiverging-class ColorMap ranging from green to red.

func SmoothPurpleOrange

func SmoothPurpleOrange() palette.DivergingColorMap

SmoothPurpleOrange is a SmoothDiverging-class ColorMap ranging from purple to orange.

Types

This section is empty.

Jump to

Keyboard shortcuts

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