Documentation
¶
Overview ¶
Package colorcrop is a Go library for cropping images by removing borders with specified color.
Index ¶
- func CmpCIE76(color1 color.Color, color2 color.Color) float64
- func CmpEuclidean(color1 color.Color, color2 color.Color) float64
- func CmpRGBComponents(color1 color.Color, color2 color.Color) float64
- func Crop(img image.Image, color color.Color, thresold float64) image.Image
- func CropWithComparator(img image.Image, color color.Color, thresold float64, comparator comparator) image.Image
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CmpEuclidean ¶
CmpEuclidean returns Euclidean difference of two colors.
func CmpRGBComponents ¶
CmpRGBComponents returns RGB components difference of two colors.
func Crop ¶
Crop returns cropped image with default comparator.
Example ¶
Simple remove of white borders.
package main
import (
"image/color"
"image/png"
"os"
"github.com/nxshock/colorcrop"
)
func main() {
// Read source image
sourceFile, _ := os.Open("img.png")
defer sourceFile.Close()
sourceImage, _ := png.Decode(sourceFile)
// Crop white border with 50% thresold
croppedImage := colorcrop.Crop(
sourceImage, // for source image
color.RGBA{255, 255, 255, 255}, // crop white border
0.5) // with 50% thresold
// Save cropped image
croppedFile, _ := os.Create("cropped.png")
defer croppedFile.Close()
png.Encode(croppedFile, croppedImage)
}
Output:
func CropWithComparator ¶
func CropWithComparator(img image.Image, color color.Color, thresold float64, comparator comparator) image.Image
CropWithComparator returns cropped image with specified comparator.
Example ¶
Remove white borders with custom color comparator.
package main
import (
"image/color"
"image/png"
"os"
"github.com/nxshock/colorcrop"
)
func main() {
// Read source image
sourceFile, _ := os.Open("img.png")
defer sourceFile.Close()
sourceImage, _ := png.Decode(sourceFile)
// Crop white border with 50% thresold
croppedImage := colorcrop.CropWithComparator(
sourceImage, // for source image
color.RGBA{255, 255, 255, 255}, // crop white border
0.5, // with 50% thresold
colorcrop.CmpCIE76) // using CIE76 standart for defining color difference
// Save cropped image
croppedFile, _ := os.Create("cropped.png")
defer croppedFile.Close()
png.Encode(croppedFile, croppedImage)
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.