img

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

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

Go to latest
Published: Jan 25, 2018 License: GPL-3.0 Imports: 10 Imported by: 0

README

Img

Package img provides basic image manipulation for RGBA and Grayscale images in Golang.
Travis Go Report Card

Gophers

Install

Assuming you have a go installation up and running:

go get github.com/thewraven/img

Quickstart

package main

import (
    "image/jpeg"
    "github.com/thewraven/img"
    "os"
)

func main() {
    file, _ := os.Open("purple_flower_peter_harrison.jpg")
    jpegImage, _ := jpeg.Decode(file)
    defer file.Close()
    //Create an RGBA image from a image.Image
    colorImage := img.NewColorFromImage(jpegImage)
    //Split channels from image
    justRed := img.Red(colorImage)
    justGreen := img.Green(colorImage)
    //Merge two images into one
    justYellow := img.Add(justRed, justGreen)

    maxx := colorImage.Bounds().Max.X - 1
    midx := maxx / 2

    //Split image vertically
    halfYellow := justYellow.WithCols(0, midx)
    halfGreen := justGreen.WithCols(midx, maxx)

    //Join two images (It's chainable!)
    resultImage := halfYellow.ConcatRight(halfGreen)

    //Save the image
    newImg, _ := os.Create("result.jpg")
    defer newImg.Close()
    jpeg.Encode(newImg, resultImage, &jpeg.Options{Quality: 80})
}
Result

(cc) Peter Harrison

Documentation

See Godoc

License

This project is licenced under the GPLv3 License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryImage

type BinaryImage [][]bool

BinaryImage is an image with logical values

func NewBinary

func NewBinary(img image.Image, div uint8) BinaryImage

NewBinary builds a binary image from an image.Image

func NewBinaryImage

func NewBinaryImage(img GrayImage, div uint8) BinaryImage

NewBinaryImage returns a BinaryImage with img's size if the color is greater than div, it's set up to true

func (BinaryImage) At

func (bi BinaryImage) At(x, y int) color.Color

At returns the related Color to the x,y position

func (BinaryImage) Bounds

func (bi BinaryImage) Bounds() image.Rectangle

Bounds returns the size of the binary image

func (BinaryImage) Clone

func (bi BinaryImage) Clone() (clone BinaryImage)

Clone returns a new instance of the binary image itself

func (BinaryImage) ColorModel

func (bi BinaryImage) ColorModel() color.Model

ColorModel returns the model of color used in BinaryImage

func (BinaryImage) Invert

func (bi BinaryImage) Invert()

func (BinaryImage) Set

func (bi BinaryImage) Set(x, y int, c color.Color)

Set wheter a black or white color into the image

func (BinaryImage) SetBinary

func (bi BinaryImage) SetBinary(x, y int, color bool)

SetBinary is a convenience method to set directly a logical value

type ColorImage

type ColorImage [][]color.Color

ColorImage describes a RGBA image which implements draw.Image

func Add

func Add(base, addition draw.Image) (dest ColorImage)

Add sums an addition into an base image and returns the result in other image.

func Blue

func Blue(img draw.Image) ColorImage

Blue remove red and green channels from the image and returns a new RGBA image with the result

func Green

func Green(img draw.Image) ColorImage

Green remove red and blue channels from the image and returns a new RGBA image with the result

func NewColorFromImage

func NewColorFromImage(img image.Image) ColorImage

NewColorFromImage recieves an image and returns a drawable RGBA image

func NewEmptyImage

func NewEmptyImage(borders image.Rectangle) ColorImage

NewEmptyImage creates a rbga image which size is equal to img

func Red

func Red(img draw.Image) ColorImage

Red remove blue and green channels from the image and returns a new RGBA image with the result

func (ColorImage) At

func (i ColorImage) At(x, y int) color.Color

At returns a color in the position [x][y].

func (ColorImage) Bounds

func (i ColorImage) Bounds() image.Rectangle

Bounds returns the size of the image

func (ColorImage) ColorModel

func (i ColorImage) ColorModel() color.Model

ColorModel returns the color model used by this implementation

func (ColorImage) ConcatBottom

func (i ColorImage) ConcatBottom(ci ColorImage) ColorImage

ConcatBottom expects a same-width image to concat at the bottom of i the result of the concatenation is returned

func (ColorImage) ConcatRight

func (i ColorImage) ConcatRight(ci ColorImage) ColorImage

ConcatRight expects a same-heigth image to concat at the left of i the result of the concatenation is returned

func (ColorImage) Contract

func (i ColorImage) Contract(scale float64, offset float64) (ci ColorImage)

Contract scales the color of the actual image to a specified range

func (ColorImage) Set

func (i ColorImage) Set(x, y int, c color.Color)

Set a color into the position [x][y]

func (ColorImage) WithCols

func (i ColorImage) WithCols(start, end int) ColorImage

WithCols slices the columns of an image and return the segment into another image

func (ColorImage) WithRows

func (i ColorImage) WithRows(start, end int) ColorImage

WithRows slices the rows of an image and return the segment into another image

type Evaluation

type Evaluation func(c color.Color) bool

type FilterOptions

type FilterOptions struct {
	Percentage float64
	Dimensions image.Point
	Exponent   int
}

FilterOptions defines options for a filter to apply

type FilterType

type FilterType int

FilterType defines a kind of filter applied to an image

const (
	//SaltAndPepper is the Salt & Pepper filter
	SaltAndPepper FilterType = 1
	//Average filter applies an average filter for each pixel on the image
	Average FilterType = 2
	//ArithmeticMean filter
	ArithmeticMean FilterType = 3
	//HarmonicMean filter
	HarmonicMean FilterType = 4
	//ContraharmonicMean filter
	ContraharmonicMean FilterType = 5
	//Fashion filter
	Fashion FilterType = 6
	//Minimum filter
	Minimum FilterType = 7
	//Maximum filter
	Maximum FilterType = 8
)

func (FilterType) String

func (ft FilterType) String() string

type GrayImage

type GrayImage [][]color.Gray

GrayImage describes a grayscale image which implements draw.Image

func NewEmptyGrayImage

func NewEmptyGrayImage(borders image.Rectangle) GrayImage

NewEmptyGrayImage creates an grayscale image with a size equals to the recieved Rectangle

func NewGrayImage

func NewGrayImage(img image.Image) GrayImage

NewGrayImage recieves an image and returns a drawable grayscale image

func (GrayImage) At

func (gi GrayImage) At(x, y int) color.Color

At returns a color in the position [x][y]

func (GrayImage) AtGray

func (gi GrayImage) AtGray(x, y int) uint8

AtGray is a convenience method to avoid Color wrapping

func (GrayImage) Bounds

func (gi GrayImage) Bounds() image.Rectangle

Bounds returns the size of the image

func (GrayImage) Clone

func (gi GrayImage) Clone() (i GrayImage)

Clone returns a new instance of the gray image itself.

func (GrayImage) ColorModel

func (gi GrayImage) ColorModel() color.Model

ColorModel returns the color model used by this implementation

func (GrayImage) Contract

func (i GrayImage) Contract(scale float64, offset float64) (gi GrayImage)

Contract scales the gray scale image to a specified range

func (GrayImage) Filter

func (gi GrayImage) Filter(ft FilterType, fo *FilterOptions) (i GrayImage)

Filter applies a filter to an image, with the options received

func (GrayImage) Select

func (gi GrayImage) Select(min, max uint8) GrayImage

Select takes all the values inside gi between min and max inclusive and returns the result

func (GrayImage) Set

func (gi GrayImage) Set(x, y int, c color.Color)

Set a color into the position [x][y]

func (GrayImage) SetGray

func (gi GrayImage) SetGray(x, y int, gray uint8)

SetGray is a convenience method to avoid Color wrapping

type Histogram

type Histogram map[uint8]int

Histogram represents the occurrence of a level of color into an image.

func GetHistogram

func GetHistogram(img image.Image) (h []Histogram)

GetHistogram creates an histogram per channel, which counts the occurrences of a color

type RGBAScanner

type RGBAScanner struct {
	// contains filtered or unexported fields
}

func NewRGBAScanner

func NewRGBAScanner(i image.Image, ev Evaluation) *RGBAScanner

func (*RGBAScanner) DrawObjects

func (s *RGBAScanner) DrawObjects(c color.Color) (ci ColorImage)

DrawObjects draw each object found in a specified color inside ci

func (*RGBAScanner) Filter

func (s *RGBAScanner) Filter(minSz int) int

Filter discarts from the object set, those which size is less than minSz

func (*RGBAScanner) SearchObjects

func (s *RGBAScanner) SearchObjects() int

SearchObjects count the objects found in the image and save them for later use

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner finds objects in a binary image.

func NewScanner

func NewScanner(i BinaryImage) *Scanner

NewScanner creates a scanner

func (*Scanner) DrawObjects

func (s *Scanner) DrawObjects() (ci ColorImage)

DrawObjects draw each object found in a random color inside ci

func (*Scanner) Filter

func (s *Scanner) Filter(minSz int) int

Filter discarts from the object set, those which size is less than minSz

func (*Scanner) SearchObjects

func (s *Scanner) SearchObjects() int

SearchObjects count the objects found in the image and save them for later use

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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