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%
原始图像
处理后图像
在当前计算的长度不小于g字符串长度时,需要比较c串对应长度的哈希值与g的哈希值,如果相同,则需要更新当前的计算哈希的下标。 代码参考: OJ/hackerrank/Gift Boxes at master · wuli2496/OJ · GitHub
2021年4月30日,英语考核之TED演讲稿。 自选主题:彩礼(betrothal gifts) 彩礼相关信息 彩礼是中国古代婚嫁习俗之一,又称订亲财礼、聘礼、聘财等。 古代的彩礼 中国旧时婚姻的缔结,有在婚姻约定初步达成时互相赠送聘金、聘礼的习俗,这种聘金、聘礼俗称“彩礼”。 在古代的订婚仪式上,男方家庭会以订婚男子的名义送给女方一份由寓意喜庆的物品构成的“彩礼”。女方家庭收受彩礼后,也会赠送男
Description Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres
题目描述 题解 假设亮度加 c ( c ∈ [ − m , m ] ) c(c \in [-m,m]) c(c∈[−m,m]) ,将 b b b 数组延长两倍,假设 b b b 数组从第 k k k 个位置开始匹配,那我们要求的就是 min k = 0 n − 1 { ∑ i = 0 n − 1 ( a i − b k + i + c ) 2 } \min_{k=0}^{n-1}\{\sum_
You have n gifts and you want to give all of them to children. Of course, you don’t want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of ai candies and bi
My best friend Willi lost his just 2 weeks ago. 2 years as Texi drive make him tire.Maybe it's time to have a rest. He always says he will not drive for others,he want be a big boss.But that is not p
Greedy Gift Givers The Problem This problem involves determining, for a group of gift-giving friends, how much more each person gives than they receive (and vice versa for those that view gift-givin
题目传送门 题意: 给定 T ( T < = 100 ) T(T<=100) T(T<=100)组 A , B , C , P ( A , B , C , P < = 1 e 8 ) A,B,C,P(A,B,C,P<=1e8) A,B,C,P(A,B,C,P<=1e8),问你每组的数组中,有多少种方法使得 A x + B y + C z = P Ax+By+Cz=P Ax+By+Cz=P。保证 C
It really is practically any custom made lately to want 'Merry Christmas' by using Holiday products. Existing tradition regarding giving products about Holiday emerged directly into famous training ne
May 26th, 2009 Considering a gift of gold Tiffany Jewellery for someone special or as a treat for yourself, take some time to learn the terms used in the industry. Here¡¯s some information to help yo
本文向大家介绍Swift语言过滤,包括了Swift语言过滤的使用技巧和注意事项,需要的朋友参考一下 示例 通过从流中选择通过特定条件的元素来创建流称为过滤
我想在下面的情况下请求你的帮助。 http://blog.cloudera.com/blog/2012/10/analysing-twitter-data-with-hadoop-part-2-getting-data-with-flume/ github.com/cloudera/cdh-twitter-example 我下载了源代码,并在更新了pom.xml中的版本后重新构建了flume-so
贡献者:xixici Apache Thrift 是跨平台跨语言的开发框架。HBase 包含了 Thrift API 和过滤语言。Thrift API 依赖于客户端和服务器进程。 你可以在服务端和客户端维 Thrift 设置安全身份验证,参照 Client-side Configuration for Secure Operation - Thrift Gateway 和 Configure th
LiteIDE LiteIDE是一款开源、跨平台的轻量级Go语言集成开发环境(IDE)。 支持的操作系统 Windows x86 (32-bit or 64-bit) Linux x86 (32-bit or 64-bit) 下载地址 :http://sourceforge.net/projects/liteide/files/ 源码地址 :https://github.com/visualfc/
上下文:我试图用Java创建一个动画。动画是简单地采取一个图像,并使它出现从最暗的像素到最亮。 问题:定义像素转换的内部算法不是我的问题。我对Java和一般计算都是新手。我做了一些研究,知道有很多API有助于图像筛选/转换。我的问题是表现,理解它。 对于实现,我创建了一个方法,它执行以下操作: 接收BufferedImage。 获取BufferedImage的WritableRaster。 使用s
3.2. 安装C语言工具 Go的工具链采用C语言编写,构建需要安装以下开发工具: GCC, C语言标准库, Bison, make, awk, 和 ed (编辑器). 对于 OS X 系统,以上工具是Xcode的一部分。 对于 Ubuntu/Debian 系统,运行安装命令: sudo apt-get install bison ed gawk gcc libc6-dev make
9.1 用外部语言写过滤器 9.1.1 混合编程场景介绍 本章来讨论 VimL 与其他语言混合编程的话题。这“混合”编程可能不是很准确的定义,也 许涉及不同层面的场景应用。在上一章介绍的异步编程也算是其中一种吧。不过如果所调 用的外部程序是别人已经写好的(或者是系统提供的经典工具),那用户就只能适应其提 供的接口或输出,在 vim 端几乎没什么可干预的。但如果利用通道连接的另一端的程序 ,也要自己
画布定位 先看这张图: > x <- c(1,2,3) > y <- c(1,3,4) > data <- data.frame(x,y) > ggplot(data, aes(x = x, y = y)) + geom_point() 如果我们希望让画布再大一些,让这三个点集中一些怎么办?我们可以调整画布的坐标范围,以下两种方法效果是一样的: > ggplot(data, aes(x = x