Esempio n. 1
0
func Auto(img image.Image, ch Channel) image.Image {
	var lightest, darkest float64
	lightest = 0.0
	darkest = 1.0

	utils.EachColor(img, func(c color.Color) {
		v := ch.Get(c)

		if v > lightest {
			lightest = v
		}
		if v < darkest {
			darkest = v
		}
	})

	// Use linear stretching algorithm
	//   v = (v - inLow) * ((outUp - outLow) / (inUp - inLow)) + outLow
	return utils.MapColor(img, func(c color.Color) color.Color {
		v := ch.Get(c)
		v = linearScale(v, darkest, lightest)

		return ch.Set(c, v)
	})
}
Esempio n. 2
0
// AutoBlack finds the darkest colour in the image and makes it black, adjusting
// the colours of every other point to achieve the same distribution.
func AutoBlack(img image.Image, ch Channel) image.Image {
	var darkest float64 = 1.0

	utils.EachColor(img, func(c color.Color) {
		v := ch.Get(c)

		if v < darkest {
			darkest = v
		}
	})

	return SetBlack(img, ch, darkest)
}
Esempio n. 3
0
func AutoWhite(img image.Image, ch Channel) image.Image {
	var lightest float64 = 0.0

	utils.EachColor(img, func(c color.Color) {
		v := ch.Get(c)

		if v > lightest {
			lightest = v
		}
	})

	return SetWhite(img, ch, lightest)
}