imgo

package module
v0.0.0-...-7856534 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 11 Imported by: 0

README

imgo

golang图像处理工具库,图像相似度计算,图像二值化(golang image process lib)

目前只支持jpg,png

GoDoc

安装
go get github.com/Comdex/imgo
示例
package main

import(
	"github.com/Comdex/imgo"
)

func main(){
    //如果读取出错会panic,返回图像矩阵img
    //img[height][width][4],height为图像高度,width为图像宽度
    //img[height][width][4]为第height行第width列上像素点的RGBA数值数组,值范围为0-255
	//如img[150][20][0]是150行20列处像素的红色值,img[150][20][1]是150行20列处像素的绿
	//色值,img[150][20][2]是150行20列处像素的蓝色值,img[150][20][3]是150行20列处像素
	//的alpha数值,一般用作不透明度参数,如果一个像素的alpha通道数值为0%,那它就是完全透明的.
    img:=imgo.MustRead("example/test.jpg")
	
	//对原图像矩阵进行日落效果处理
	img2:=imgo.SunsetEffect(img)
	
	//保存为jpeg,100为质量,1-100
	err:=imgo.SaveAsJPEG("example/new.jpg",img2,100)
	if err!=nil {
		panic(err)
	}
}

计算两张图片的余弦相似度

	cos,err:=imgo.CosineSimilarity("test1.jpg","test2.jpg")
	if err!=nil{
		panic(err)
	}
	fmt.Println(cos)

2015.8.23 update :添加使用感知哈希算法的GetFingerprint函数获取图片的“指纹”字符串

	fp,err:=imgo.GetFingerprint("test1.jpg")
	if err!=nil {
		panic(err)
	}
	fmt.Println(fp)//输出64位的01字符串
效果

原图
横向镜像imgo.HorizontalMirror
日落imgo.SunsetEffect
负片imgo.NegativeFilmEffect
调整亮度imgo.AdjustBrightness
垂直镜像imgo.VerticalMirror

更多api及帮助请访问:http://godoc.org/github.com/Comdex/imgo

版权

本项目采用MIT开源授权许可证,完整的授权说明可在LICENSE文件中找到。

Documentation

Overview

package imgo is a golang image process lib

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustBrightness

func AdjustBrightness(src [][][]uint8, light float64) (imgMatrix [][][]uint8, err error)

func Base64ToImg

func Base64ToImg(encodeString string, dstFile string) error

Base64ToImg create a image file named dstFile from base64 encodeString.

func Binaryzation

func Binaryzation(src [][][]uint8, threshold int) [][][]uint8

binaryzation process of image matrix , threshold can use 127 to test

func CosineSimilarity

func CosineSimilarity(src1 string, src2 string) (cossimi float64, err error)

calculate Cosine Similarity of two images, input two file path

func DecodeImage

func DecodeImage(filePath string) (img image.Image, err error)

decode a image and retrun golang image interface

func Dot

func Dot(x []uint8, y []uint8) float64

func GetFingerprint

func GetFingerprint(src string) (fp string, err error)

GetFingerprint use Perceptual Hash Algorithm to get fingerprint from a pircture

func GetImageHeight

func GetImageHeight(img image.Image) int

func GetImageWidth

func GetImageWidth(img image.Image) int

func HorizontalMirror

func HorizontalMirror(src [][][]uint8) [][][]uint8

func HorizontalMirrorPart

func HorizontalMirrorPart(src [][][]uint8) [][][]uint8

make a mirror of src

func ImageFusion

func ImageFusion(src1 string, src2 string) (imgMatrix [][][]uint8, err error)

fuse two images(filepath) and the size of new image is as src1

func Img2Base64

func Img2Base64(filepath string) (encodeString string, err error)

Img2Base64 produce a base64 string from a image file.

func Img2Base64ByGoImage

func Img2Base64ByGoImage(img image.Image) (encodeString string, err error)

Img2base64ByGoImage produce a base64 string from Image interface.

func Iterator

func Iterator(filepath string, iter IterFunc) (imgMatrix [][][]uint8, err error)

func Matrix2Vector

func Matrix2Vector(imgMatrix [][][]uint8) (vector []uint8)

func MustRead

func MustRead(filepath string) (imgMatrix [][][]uint8)

read a image return a image matrix , if appear an error it will panic

func NegativeFilmEffect

func NegativeFilmEffect(src [][][]uint8) [][][]uint8

input a image as src , return a image matrix by negativefilmeffect process

func New3DSlice

func New3DSlice(x int, y int, z int) (theSlice [][][]uint8)

create a three dimenson slice

func NewRGBAMatrix

func NewRGBAMatrix(height int, width int) (rgbaMatrix [][][]uint8)

create a new rgba matrix

func RGB2Gray

func RGB2Gray(src [][][]uint8) [][][]uint8

func Read

func Read(imgOrPath interface{}) (imgMatrix [][][]uint8, err error)

read a image return a image matrix by path or image

func Resize

func Resize(src *image.NRGBA, width int, height int) *image.NRGBA

resize size of image

func ResizeForMatrix

func ResizeForMatrix(filepath string, width int, height int) (imgMatrix [][][]uint8, err error)

func Rotate

func Rotate(src [][][]uint8) [][][]uint8

func SaveAsJPEG

func SaveAsJPEG(filepath string, imgMatrix [][][]uint8, quality int) error

save a image matrix as a jpeg,if unsuccessful it will return a error,quality must be 1 to 100

func SaveAsPNG

func SaveAsPNG(filepath string, imgMatrix [][][]uint8) error

save a image matrix as a png , if unsuccessful it will return a error

func SetOpacity

func SetOpacity(src [][][]uint8, opacity float64) (imgMatrix [][][]uint8, err error)

set the opacity of image matrix , opacity must be 0.0 to 1.0

func SunsetEffect

func SunsetEffect(src [][][]uint8) [][][]uint8

input a image matrix as src , return a image matrix by sunseteffect process

func VerticalMirror

func VerticalMirror(src [][][]uint8) [][][]uint8

func VerticalMirrorPart

func VerticalMirrorPart(src [][][]uint8) [][][]uint8

Types

type IterFunc

type IterFunc func(i int, j int, k int, src [][][]uint8) [][][]uint8

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL