average blend method

This commit is contained in:
Ali Gator 2022-05-02 13:25:50 +02:00
parent 5f7508fe3d
commit 603871d556
3 changed files with 25 additions and 1 deletions

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# Requirements
- go >= 1.16.2
# Install
Just `git clone`, `cd pixelweaver` and `go build` bro
# Usage
See `pixelweaver -help` for all available options
Example : Blends three random pictures stored in specified folder, using averaging, with a sepia filter
`pixelweaver -amount 3 -input ~/Photos -blending average -sepia`
# Resources
- [image package documentation on pkg.go.dev](https://pkg.go.dev/image)
- [Sighack - Averaging RGB Colors the Right Way](https://sighack.com/post/averaging-rgb-colors-the-right-way)
- [Sau Sheong - Image processing with Go](https://go-recipes.dev/more-working-with-images-in-go-30b11ab2a9f0?gi=3bb0ce492e2e)

View File

@ -195,6 +195,10 @@ func filter(pixel color.Color) color.Color {
return pixel
}
func average(fc uint8, bc uint8, fa uint8) float64 {
return (float64(fc)/2 + float64(bc)/2)
}
func darken(fc uint8, bc uint8, fa uint8) float64 {
return math.Min(float64(fc), float64(bc))
}
@ -214,6 +218,8 @@ func blend(fc uint8, bc uint8, fa uint8, ba uint8) float64 {
switch ConfigRegister.Method {
case "darken":
newValue = darken(fc, bc, fa)
case "average":
newValue = average(fc, bc, fa)
case "ligten":
newValue = lighten(fc, bc, fa)
case "fuckyfun":

View File

@ -48,7 +48,7 @@ func (c *Config) SetOutputDimensions() {
func initConfigRegister() {
// command line arguments
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun")
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, average, fuckyfun")
flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory")
flag.StringVar(&ConfigRegister.InputDir, "input", "/home/gator/Photos", "Input directory. Where to look the images from")
flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set")