internal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashSize  = 32
	ImageSize = 512
)

Variables

View Source
var (
	ErrMatrixLength        = errors.New("pdq: matrix length is not the expected 64x64")
	ErrTorbenElementLength = errors.New("pdq: expected 256 elements for torben median")
	ErrQuantizeLength      = errors.New("pdq: expected 16x16 for DCT quantization")
	ErrDihedralDCTSize     = errors.New("pdq: expected 16x16 for DCT dihedral")
)

Functions

func ComputeQuality

func ComputeQuality(matrix []float32) (int, error)

ComputeQuality calculates a quality score based on gradient differences in a 64x64 matrix of float32 values. Returns an error if the input matrix does not match the required dimensions.

func DCT64To16

func DCT64To16(input []float32) []float32

DCT64To16 performs a 2D Discrete Cosine Transform (DCT) to convert a 64x64 input into a reduced 16x16 output matrix.

func DihedralHashes

func DihedralHashes(dct []float32) ([8][16]uint16, error)

DihedralHashes generates 8 quantized hash representations by applying dihedral transformations to a 16x16 DCT array.

Sign conventions are taken directly from the C++ reference (pdqhashing.cpp):

orig      rot90     rot180    rot270
noxpose   xpose     noxpose   xpose
+ + + +   - + - +   + - + -   - - - -
+ + + +   - + - +   - + - +   + + + +
+ + + +   - + - +   + - + -   - - - -
+ + + +   - + - +   - + - +   + + + +

flipx     flipy     flipplus  flipminus
noxpose   noxpose   xpose     xpose
- - - -   - + - +   + + + +   + - + -
+ + + +   - + - +   + + + +   - + - +
- - - -   - + - +   + + + +   + - + -
+ + + +   - + - +   + + + +   - + - +

For transposing transforms the C++ writes B[j][i] = ±A[i][j]. Our closures receive (outRow, outCol); the mapping is outRow=j_cpp, outCol=i_cpp, so at(outCol, outRow) reads A[i][j].

func JaroszFilter

func JaroszFilter(src []float32, numRows, numCols int) ([]float32, error)

JaroszFilter applies a 2-pass filter to src and returns a downsampled 64x64 result.

func PrepareImage

func PrepareImage(src image.Image) (luma []float32, numRows, numCols int, err error)

PrepareImage conditionally downscales src to at most ImageSize in either dimension, then returns the pixel data as a float32 luminance array along with the actual processing dimensions.

Small images are processed at their native size. Only images larger than ImageSize in either dimension are downscaled.

func Quantize

func Quantize(input []float32, median float32) ([16]uint16, error)

Quantize generates a 16-element hash by thresholding each value of a 16x16 input array against the provided median. Returns an error if the input array length is not 256.

func ResizeBilinear

func ResizeBilinear(src image.Image, size int) *image.RGBA

ResizeBilinear resizes the given image using bilinear interpolation to the specified square size (width and height).

func ToLuminance

func ToLuminance(src *image.RGBA, numRows, numCols int) ([]float32, error)

ToLuminance converts an RGBA image to a grayscale luminance representation.

func ToRGBA

func ToRGBA(src image.Image) *image.RGBA

ToRGBA converts any image.Image to *image.RGBA without resizing.

func TorbenMedian

func TorbenMedian(m []float32) (float32, error)

TorbenMedian calculates the median of a float32 slice using Torben's algorithm, optimized for a fixed slice size of 256. Returns the median value or an error if the input slice length is not 256.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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