Go 语言的图像过滤工具包 Gift

码农软件 · 软件分类 · 图形/图像处理 · 2019-09-06 06:14:28

软件介绍

Gift 包提供一整套有用的图像处理过滤器。

完全使用 Go 语言,没有 Go 标准库之外的外部依赖。

安装/更新

go get -u github.com/disintegration/gift

文档

http://godoc.org/github.com/disintegration/gift

快速开始

// 1. 创建一个新的 GIFT 过滤器列表以及添加一些过滤器
g := gift.New(
    gift.Resize(800, 0, gift.LanczosResampling),
    gift.UnsharpMask(1.0, 1.0, 0.0),
)
// 2. 创建一个相应大小的新图像
// dst 是一个新的目标图像,src 是原始图像
dst := image.NewRGBA(g.Bounds(src.Bounds()))
// 3. 使用 Draw 函数将过滤器应用到 src 并将结果存储到 dst
g.Draw(dst, src)

用法

New 函数用于创建过滤器的序列:

g := gift.New(
    gift.Grayscale(),
    gift.Contrast(10),
)

过滤器也可以使用 Add 方法被添加:

g.Add(GaussianBlur(2))

Bounds 方法获取原始图像的界限并为目的图像返回相应的界限以适应结果(例如使用 Resize 或 Rotate 过滤器后)

dst := image.NewRGBA(g.Bounds(src.Bounds()))

支持的过滤器

转换

  • Crop(rect image.Rectangle)

  • CropToSize(width, height int, anchor Anchor)

  • FlipHorizontal()

  • FlipVertical()

  • Resize(width, height int, resampling Resampling)

  • ResizeToFill(width, height int, resampling Resampling, anchor Anchor)

  • ResizeToFit(width, height int, resampling Resampling)

  • Rotate(angle float32, backgroundColor color.Color, interpolation Interpolation)

  • Rotate180()

  • Rotate270()

  • Rotate90()

  • Transpose()

  • Transverse()

调整与效果

  • Brightness(percentage float32)

  • ColorBalance(percentageRed, percentageGreen, percentageBlue float32)

  • ColorFunc(fn func(r0, g0, b0, a0 float32) (r, g, b, a float32))

  • Colorize(hue, saturation, percentage float32)

  • ColorspaceLinearToSRGB()

  • ColorspaceSRGBToLinear()

  • Contrast(percentage float32)

  • Convolution(kernel []float32, normalize, alpha, abs bool, delta float32)

  • Gamma(gamma float32)

  • GaussianBlur(sigma float32)

  • Grayscale()

  • Hue(shift float32)

  • Invert()

  • Maximum(ksize int, disk bool)

  • Mean(ksize int, disk bool)

  • Median(ksize int, disk bool)

  • Minimum(ksize int, disk bool)

  • Pixelate(size int)

  • Saturation(percentage float32)

  • Sepia(percentage float32)

  • Sigmoid(midpoint, factor float32)

  • Sobel()

  • UnsharpMask(sigma, amount, thresold float32)


过滤器示例

调整之使用 lanczos 算法重新采样

原始图像

处理后图像

调整之使用线性算法重采样

原始图像

处理后图像

调整大小以适应 160x160 像素边框

原始图像

处理后图像

旋转 270 度

原始图像

处理后图像

水平翻转

原始图像

处理后图像

饱和度提高 50%

原始图像

处理后图像

本文地址:https://codercto.com/soft/d/13973.html

程序开发心理学

程序开发心理学

(美)杰拉尔德·温伯格 / 邓俊辉 / 清华大学出版社 / 2004-1-1 / 39.00元

本书开创"以人为本"研究方法的先驱,在长达25年的岁月中一直保持活力,至今仍在继续。1997年,本书作者温伯格因其在软件领域的杰出贡献,被美国计算机博物馆的计算机名人堂选为首批5位成员之一。 在计算机界,还没有任何一本计算机方面的书,在初次出版之后,能够在长达25年的岁月中一直保持活力--而且这种活力到今天仍在继续。《程序开发心理学》是开创"以人为本"研究方法的先驱,它以其对程序员们在智力、......一起来看看 《程序开发心理学》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具