colorspace

package
v1.1.19 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 8 Imported by: 3

README

The color axes in the human brain are R-G and B-Y. In color speak L = R, M = G, S = B (long, med, short wavelength) –- it is very clear that this is how color is coded in the LGN thalamus.

Color spaces and computational color

i.e., how to quickly approximate color vision..

Color in V1

Two effective populations of cells in V1: double-opponent and single-opponent

  • Double-opponent are most common, and define an edge in color space (e.g., R-G edge) by having offset opposing lobes of a gabor (e.g., one lobe is R+G- and the other lobe is G+R-) – this gives the usual zero response for uniform illumination, but a nice contrast response. We should probably turn on color responses in general in our V1 pathway, esp if it is just RG and BY instead of all those other guys. Can also have the color just be summarized in the PI polarity independent pathway.

  • Single-opponent which are similar-sized gaussians with opponent R-G and B-Y tuning. These are much fewer, and more concentrated in these CO-blob regions, that go to the “thin” V2 stripes. But the divisions are not perfect..

Papers

  • Conway, 2001: double-opponent color sensitivity – respond to spatial changes in color, not just raw color contrast – this is key for color constancy and making the color pathway much more efficient – a single-opponent dynamic causes entire color regions to be activated, instead of just activating for changes in color, which is the key point about efficient retinal coding in the luminance domain – just code for local changes, not broad regions. BUT this type of cell is not typically found and other mechanisms exist..

  • Gegenfurtner, 2003: nature neuroscience review of color highly recommended – lots of key excerpts on page

  • Solomon & Lennie, 2007: lower-level paper with some nice diagrams and generally consistent conclusions.

  • Field et al., 2010: recording in the retina – wow! but not sure of implications.

  • Shapley & Hawken, 2011: review – lots of good stuff in here and some strong key conclusions

  • Zhang et al., 2012: implements single and double opponent mechs in various models and shows that they work well! – though they do add a R-Cyan channel, and don’t seem to actually use the single opponent channel?? not too clear about that..

  • Yang et al., 2013: uses SO and DO but not sure again about SO usage.. maybe just along way to DO.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KiT_LMSComponents = kit.Enums.AddEnum(LMSComponentsN, kit.NotBitFlag, nil)
View Source
var KiT_Opponents = kit.Enums.AddEnum(OpponentsN, kit.NotBitFlag, nil)

Functions

func LMSToComps

func LMSToComps(l, m, s float32) (lc, mc, sc, lmc, lvm, svlm, grey float32)

LMSToComps converts Long, Medium, Short cone-based responses to components incl opponents: Red - Green (LvM) and Blue - Yellow (SvLM). Includes the separate components in these subtractions as well Uses the CIECAM02 color appearance model (MoroneyFairchildHuntEtAl02) https://en.wikipedia.org/wiki/CIECAM02

func LuminanceAdaptation

func LuminanceAdaptation(bgLum float32) float32

LuminanceAdaptation implements the luminance adaptation function equals 1 at background luminance of 200 so we generally ignore it.. bgLum is background luminance -- 200 default.

func MacbethImage

func MacbethImage(img *etensor.Float32, width, height, bord int)

MacbethImage sets the Macbeth standard color test image to given tensor with given size and border width around edges. if img == nil it is created, and size enforced.

func RGBImgToLMSComps

func RGBImgToLMSComps(img image.Image, tsr *etensor.Float32, padWidth int, topZero bool)

RGBImgLMSComps converts an RGB image to corresponding LMS components including color opponents, with components as the outer-most dimension. padWidth is the amount of padding to add on all sides. topZero retains the Y=0 value at the top of the tensor -- otherwise it is flipped with Y=0 at the bottom to be consistent with the emergent / OpenGL standard coordinate system

func RGBTensorToLMSComps

func RGBTensorToLMSComps(tsr *etensor.Float32, rgb *etensor.Float32)

RGBTensorToLMSComps converts an RGB Tensor to corresponding LMS components including color opponents, with components as the outer-most dimension, and assumes rgb is 3 dimensional with outer-most dimension as RGB.

func ResponseCompression

func ResponseCompression(val float32) float32

ResponseCompression takes a 0-1 normalized LMS value and performs hyperbolic response compression. val must ALREADY have the luminance adaptation applied to it using the luminance adaptation function, which is 1 at a background luminance level of 200 = 2, so you can skip that step if you assume that level of background.

func SRGBFmLinear

func SRGBFmLinear(rl, gl, bl float32) (r, g, b float32)

SRGBFmLinear converts set of sRGB components from linear values, adding gamma correction.

func SRGBFmLinearComp

func SRGBFmLinearComp(lin float32) float32

SRGBFmLinearComp converts an sRGB rgb linear component to non-linear (gamma corrected) sRGB value Used in converting from XYZ to sRGB.

func SRGBLinToLMS_CAT02

func SRGBLinToLMS_CAT02(rl, gl, bl float32) (l, m, s float32)

SRGBLinToLMS_CAT02 converts sRGB linear to Long, Medium, Short cone-based responses, using the CAT02 transform from CIECAM02 color appearance model (MoroneyFairchildHuntEtAl02) this is good for representing adaptation but NOT apparently good for representing appearances

func SRGBLinToLMS_HPE

func SRGBLinToLMS_HPE(rl, gl, bl float32) (l, m, s float32)

SRGBLinToLMS_HPE converts sRGB linear to Long, Medium, Short cone-based responses, using the Hunt-Pointer-Estevez transform. This is closer to the actual response functions of the L,M,S cones apparently.

func SRGBLinToXYZ

func SRGBLinToXYZ(rl, gl, bl float32) (x, y, z float32)

SRGBLinToXYZ converts sRGB linear into XYZ CIE standard color space

func SRGBToLMSComps

func SRGBToLMSComps(r, g, b float32) (lc, mc, sc, lmc, lvm, svlm, grey float32)

SRGBToLMSComps converts sRGB to LMS components including opponents using the HPE cone values: Red - Green (LvM) and Blue - Yellow (SvLM). Includes the separate components in these subtractions as well. Uses the CIECAM02 color appearance model (MoroneyFairchildHuntEtAl02) https://en.wikipedia.org/wiki/CIECAM02 using the Hunt-Pointer-Estevez transform.

func SRGBToLMS_CAT02

func SRGBToLMS_CAT02(r, g, b float32) (l, m, s float32)

SRGBToLMS_CAT02 converts sRGB to Long, Medium, Short cone-based responses, using the CAT02 transform from CIECAM02 color appearance model (MoroneyFairchildHuntEtAl02)

func SRGBToLMS_HPE

func SRGBToLMS_HPE(r, g, b float32) (l, m, s float32)

SRGBToLMS_HPE converts sRGB to Long, Medium, Short cone-based responses, using the Hunt-Pointer-Estevez transform. This is closer to the actual response functions of the L,M,S cones apparently.

func SRGBToLinear

func SRGBToLinear(r, g, b float32) (rl, gl, bl float32)

SRGBToLinear converts set of sRGB components to linear values, removing gamma correction.

func SRGBToLinearComp

func SRGBToLinearComp(srgb float32) float32

SRGBToLinearComp converts an sRGB rgb component to linear space (removes gamma). Used in converting from sRGB to XYZ colors.

func SRGBToXYZ

func SRGBToXYZ(r, g, b float32) (x, y, z float32)

SRGBToXYZ converts sRGB into XYZ CIE standard color space

func XYZRenormD65

func XYZRenormD65(x, y, z float32) (xr, yr, zr float32)

#CAT_ColorSpace renormalize XZY values relative to the D65 outdoor white light values

func XYZToLMS_CAT02

func XYZToLMS_CAT02(x, y, z float32) (l, m, s float32)

XYZToLMS_CAT02 converts XYZ to Long, Medium, Short cone-based responses, using the CAT02 transform from CIECAM02 color appearance model (MoroneyFairchildHuntEtAl02)

func XYZToLMS_HPE

func XYZToLMS_HPE(x, y, z float32) (l, m, s float32)

XYZToLMS_HPE convert XYZ to Long, Medium, Short cone-based responses, using the Hunt-Pointer-Estevez transform. This is closer to the actual response functions of the L,M,S cones apparently.

func XYZToSRGB

func XYZToSRGB(x, y, z float32) (r, g, b float32)

XYZToSRGB converts XYZ CIE standard color space into sRGB

func XYZToSRGBLin

func XYZToSRGBLin(x, y, z float32) (rl, gl, bl float32)

XYZToSRGBLin converts XYZ CIE standard color space to sRGB linear

Types

type LMSComponents

type LMSComponents int

LMSComponents are different components of the LMS space including opponent contrasts and grey

const (
	// Long wavelength = Red component
	LC LMSComponents = iota

	// Medium wavelength = Green component
	MC

	// Short wavelength = Blue component
	SC

	// Long + Medium wavelength = Yellow component
	LMC

	// L - M opponent contrast: Red vs. Green
	LvMC

	// S - L+M opponent contrast: Blue vs. Yellow
	SvLMC

	// achromatic response (grey scale lightness)
	GREY

	// number of components
	LMSComponentsN
)

func (*LMSComponents) FromString

func (i *LMSComponents) FromString(s string) error

func (LMSComponents) MarshalJSON

func (ev LMSComponents) MarshalJSON() ([]byte, error)

func (LMSComponents) String

func (i LMSComponents) String() string

func (*LMSComponents) UnmarshalJSON

func (ev *LMSComponents) UnmarshalJSON(b []byte) error

type Opponents added in v1.1.11

type Opponents int

Opponents enumerates the three primary opponency channels: WhiteBlack, RedGreen, BlueYellow using colloquial "everyday" terms.

const (
	// White vs. Black greyscale
	WhiteBlack Opponents = iota

	// Red vs. Green
	RedGreen

	// Blue vs. Yellow
	BlueYellow

	// number of opponents
	OpponentsN
)

func (*Opponents) FromString added in v1.1.11

func (i *Opponents) FromString(s string) error

func (Opponents) MarshalJSON added in v1.1.11

func (ev Opponents) MarshalJSON() ([]byte, error)

func (Opponents) String added in v1.1.11

func (i Opponents) String() string

func (*Opponents) UnmarshalJSON added in v1.1.11

func (ev *Opponents) UnmarshalJSON(b []byte) error

type SRGBToOp

type SRGBToOp struct {

	// number of levels in the lookup table -- linear interpolation used
	Levels int `desc:"number of levels in the lookup table -- linear interpolation used"`

	// lookup table
	Table etensor.Float32 `desc:"lookup table"`
}

SRGBToOp implements a lookup-table for the conversion of SRGB components to LMS color opponent values. After all this, it looks like the direct computation is faster than the lookup table! In any case, it is all here and reasonably accurate (mostly under 1.0e-4 according to testing)

var TheSRGBToOp SRGBToOp

TheSRGBToOp is the instance of SRGBToOp to use

func (*SRGBToOp) Init

func (so *SRGBToOp) Init()

Init does initialization if not yet initialized

func (*SRGBToOp) InterpIdx

func (so *SRGBToOp) InterpIdx(val float32) (loi, hii int, pctlo, pcthi float32)

func (*SRGBToOp) Lookup

func (so *SRGBToOp) Lookup(r, g, b float32) (lc, mc, sc, lmc, lvm, svlm, grey float32)

Jump to

Keyboard shortcuts

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