images4

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

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 8 Imported by: 0

README

Documentation

Index

Constants

View Source
const (

	// Image resolution of the icon is very small
	// (11x11 pixels), therefore original image details
	// are lost in downsampling, except when source images
	// have very low resolution (e.g. favicons or simple
	// logos). This is useful from the privacy perspective
	// if you are to use generated icons in a large searchable
	// database.
	IconSize = 11 // Exported to be used in package imagehash.

)

Variables

This section is empty.

Functions

func CustomSimilar

func CustomSimilar(iconA, iconB IconT, coeff CustomCoefficients) bool

CustomSimilar is like Similar, except it allows changing default thresholds by multiplying them. The practically useful range of the coefficients is [0, 1.0), but can be equal or larger than 1 if necessary. All coefficients set to 0 correspond to identical images, for example an image file copy. All coefficients equal to 1 make func CustomSimilar equivalent to func Similar.

func CustomSimilar90270

func CustomSimilar90270(iconA, iconB IconT, coeff CustomCoefficients) bool

Similar90270 works like Similar, but also considers rotations of ±90°. Those are rotations users might reasonably often do.

func DefaultThresholds

func DefaultThresholds()

Print default thresholds for func Similar.

func EucMetric

func EucMetric(iconA, iconB IconT) (m1, m2, m3 float64)

EucMetric returns Euclidean distances between 2 icons. These are 3 metrics corresponding to each color channel. Distances are squared, not to waste CPU on square root calculations. Note: color channels of icons are YCbCr (not RGB).

func Get

func Get(icon IconT, size int, p image.Point) (c1, c2, c3 float64)

Get reads pixel values in an icon at a point. c1, c2, c3 are color values for each channel (RGB for example). Exported to be used in package imagehash.

func Open

func Open(path string) (img image.Image, err error)

Open opens and decodes an image file for a given path.

func PropMetric

func PropMetric(iconA, iconB IconT) (m float64)

PropMetric gives image proportion similarity metric for image A and B. The smaller the metric the more similar are images by their x-y size.

func ResizeByNearest

func ResizeByNearest(
	src image.Image, dstSize image.Point) (
	dst image.RGBA, srcSize image.Point)

ResizeByNearest resizes an image to the destination size with the nearest neighbour method. It also returns the source image size.

func SaveToJPG

func SaveToJPG(img *image.RGBA, path string, quality int)

SaveToJPG encodes and saves image.RGBA to a file.

func SaveToPNG

func SaveToPNG(img *image.RGBA, path string)

SaveToPNG encodes and saves image.RGBA to a file.

func Set

func Set(icon IconT, size int, p image.Point, c1, c2, c3 float64)

Set places pixel values in an icon at a point. c1, c2, c3 are color values for each channel (RGB for example). Size is icon size. Exported to be used in package imagehash.

func Similar

func Similar(iconA, iconB IconT) bool

Similar returns similarity verdict based on Euclidean and proportion similarity.

func Similar90270

func Similar90270(iconA, iconB IconT) bool

Similar90270 works like Similar, but also considers rotations of ±90°. Those are rotations users might reasonably often do.

Types

type CustomCoefficients

type CustomCoefficients struct {
	Y    float64 // Luma (grayscale information).
	Cb   float64 // Chrominance b (color information).
	Cr   float64 // Chrominance r (color information).
	Prop float64 // Proportion tolerance (how similar are image borders).
}

Threshold multiplication coefficients for func CustomSimilar. When all values equal 1.0 func CustomSimilar is equivalent to func Similar. By setting those values less than 1, similarity comparison becomes stricter (more precise). Values larger than 1 will generalize more and show more false positives. When uncertain, setting all coefficients to 1.0 is the safe starting point.

type IconT

type IconT struct {
	Pixels  []uint16    // Visual signature.
	ImgSize image.Point // Original image size.
}

Icon has square shape. Its pixels are uint16 values in 3 channels. uint16 is intentional to preserve color relationships from the full-size image. It is a 255- premultiplied color value in [0, 255] range.

func EmptyIcon

func EmptyIcon() (icon IconT)

EmptyIcon is an icon constructor in case you need an icon with nil values, for example for convenient error handling. Then you can use icon.Pixels == nil condition.

func Icon

func Icon(img image.Image) IconT

Icon generates a normalized image signature ("icon"). Generated icons can then be stored in a database and used for comparison. Icon is the recommended function, vs less robust func IconNN.

func IconNN

func IconNN(img image.Image) IconT

IconNN generates a NON-normalized image signature (icon). Icons made with IconNN can be used instead of icons made with func Icon, but mostly for experimental purposes, allowing better understand how the algorithm works, or performing less agressive customized normalization. Not for general use.

func OpenAsIcon

func OpenAsIcon(path string) (*IconT, error)

func Rotate90

func Rotate90(icon IconT) IconT

Rotate rotates an icon by 90 degrees clockwise.

func (IconT) ToRGBA

func (icon IconT) ToRGBA(size int) *image.RGBA

ToRGBA transforms a sized icon to image.RGBA. This is an auxiliary function to visually evaluate an icon.

Jump to

Keyboard shortcuts

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