How to apply color correction and adjustment to an image in Go?

To apply color correction and adjustment to an image in Go, you can use the github.com/disintegration/imaging package. Here's an example of how you can do it:

  1. Install the imaging package by running the following command:
go get -u github.com/disintegration/imaging
  1. Import the necessary packages in your Go code:
import ( "github.com/disintegration/imaging" "image" "image/color" )
  1. Load your image file into a Go image.Image object:
srcImage, err := imaging.Open("path/to/your/image.jpg") if err != nil { log.Fatal(err) }
  1. Apply color correction or adjustments to the image using the provided functions from the imaging package. For example, you can apply a sepia filter:
sepiaImage := imaging.AdjustFunc(srcImage, func(c color.NRGBA) color.NRGBA { return color.NRGBA{ R: uint8(float64(c.R)*0.393 + float64(c.G)*0.769 + float64(c.B)*0.189), G: uint8(float64(c.R)*0.349 + float64(c.G)*0.686 + float64(c.B)*0.168), B: uint8(float64(c.R)*0.272 + float64(c.G)*0.534 + float64(c.B)*0.131), A: c.A, } })
  1. Save the modified image to a file:
err = imaging.Save(sepiaImage, "path/to/save/sepia_image.jpg") if err != nil { log.Fatal(err) }

You can explore other functions provided by the imaging package to perform various color correction and adjustments, such as changing brightness, contrast, saturation, etc.