Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeQuality(matrix []float32) (int, error)
- func DCT64To16(input []float32) []float32
- func DihedralHashes(dct []float32) ([8][16]uint16, error)
- func JaroszFilter(src []float32, numRows, numCols int) ([]float32, error)
- func PrepareImage(src image.Image) (luma []float32, numRows, numCols int, err error)
- func Quantize(input []float32, median float32) ([16]uint16, error)
- func ResizeBilinear(src image.Image, size int) *image.RGBA
- func ToLuminance(src *image.RGBA, numRows, numCols int) ([]float32, error)
- func ToRGBA(src image.Image) *image.RGBA
- func TorbenMedian(m []float32) (float32, error)
Constants ¶
const ( HashSize = 32 ImageSize = 512 )
Variables ¶
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 ¶
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 ¶
DCT64To16 performs a 2D Discrete Cosine Transform (DCT) to convert a 64x64 input into a reduced 16x16 output matrix.
func DihedralHashes ¶
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 ¶
JaroszFilter applies a 2-pass filter to src and returns a downsampled 64x64 result.
func PrepareImage ¶
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 ¶
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 ¶
ResizeBilinear resizes the given image using bilinear interpolation to the specified square size (width and height).
func ToLuminance ¶
ToLuminance converts an RGBA image to a grayscale luminance representation.
func TorbenMedian ¶
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.