enhance

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 5 Imported by: 0

README

enhance

Package enhance is a Go implementation for enhancing photographs (adjusting brightness, contrast, etc.)

This project aims to reproduce https://github.com/yuki-koyama/enhancer.

Usage

package main

import (
	"image"
	"image/jpeg"
	"log"
	"os"

	"changkun.de/x/enhance"
)

func main() {
	f, err := os.Open("testdata/1.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	img, err := jpeg.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	enhanced := enhance.Image(img, enhance.Params{
		Brightness:  .5,
		Contrast:    .5,
		Saturation:  .5,
		Temperature: .5,
		Tint:        .5,
	})

	f, err = os.Create("testdata/enhanced.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	if err := jpeg.Encode(f, enhanced, nil); err != nil {
		log.Fatal(err)
	}
}

License

MIT

Documentation

Overview

Package enhance provides image enhancement algorithms for adjusting brightness, contrast, saturation, temperature, and tint.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Image

func Image(img image.Image, params Params) *image.RGBA

Image enhances a given image.Image and returns a new image.RGBA.

This method reproduces https://github.com/yuki-koyama/enhancer.

Example
package main

import (
	"image/jpeg"
	"log"
	"os"

	"changkun.de/x/enhance"
)

func main() {
	f, err := os.Open("testdata/1.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	img, err := jpeg.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	enhanced := enhance.Image(img, enhance.Params{
		Brightness:  .5,
		Contrast:    .5,
		Saturation:  .5,
		Temperature: .5,
		Tint:        .5,
	})
	f, err = os.Create("testdata/enhanced.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	if err := jpeg.Encode(f, enhanced, nil); err != nil {
		log.Fatal(err)
	}

}
Output:

Types

type Color

type Color struct {
	R, G, B float64
}

Color RGB from 0 to 1.

func NewColor

func NewColor(c color.RGBA) Color

func Pixel

func Pixel(p Color, params Params) Color

Pixel changes the color of a pixel based on the given parameters.

func (Color) ToRGBA

func (c Color) ToRGBA() color.RGBA

type Params

type Params struct {
	Brightness  float64 `json:"brightness"`
	Contrast    float64 `json:"contrast"`
	Saturation  float64 `json:"saturation"`
	Temperature float64 `json:"temperature"`
	Tint        float64 `json:"tint"`
}

Params defines the parameters for image enhancement. The values should in range [0, 1].

Jump to

Keyboard shortcuts

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