imgsmlr

imgsmlr

imgsmlr : Image similarity with haar

Overview

ID Extension Package Version Category License Language
2830
imgsmlr
imgsmlr
1.0
FEAT
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
age
hll
rum
pg_graphql
pg_jsonschema
jsquery
pg_hint_plan
hypopg

breaks on el10

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.0
18
17
16
15
14
imgsmlr -
RPM
PIGSTY
1.0
18
17
16
15
14
imgsmlr_$v -
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-imgsmlr -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
MISS
MISS
MISS
MISS
MISS
el10.aarch64
MISS
MISS
MISS
MISS
MISS
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
MISS
MISS
MISS
MISS
MISS
d13.aarch64
MISS
MISS
MISS
MISS
MISS
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
Package Version OS ORG SIZE File URL
imgsmlr_18 1.0 el8.x86_64 pigsty 21.6 KiB imgsmlr_18-1.0-2PIGSTY.el8.x86_64.rpm
imgsmlr_18 1.0 el8.aarch64 pigsty 21.2 KiB imgsmlr_18-1.0-2PIGSTY.el8.aarch64.rpm
imgsmlr_18 1.0 el9.x86_64 pigsty 21.2 KiB imgsmlr_18-1.0-2PIGSTY.el9.x86_64.rpm
imgsmlr_18 1.0 el9.aarch64 pigsty 20.9 KiB imgsmlr_18-1.0-2PIGSTY.el9.aarch64.rpm
postgresql-18-imgsmlr 1.0 d12.x86_64 pigsty 30.9 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-imgsmlr 1.0 d12.aarch64 pigsty 30.2 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-imgsmlr 1.0 u22.x86_64 pigsty 32.9 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-imgsmlr 1.0 u22.aarch64 pigsty 32.1 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-imgsmlr 1.0 u24.x86_64 pigsty 32.3 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
postgresql-18-imgsmlr 1.0 u24.aarch64 pigsty 31.6 KiB postgresql-18-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
imgsmlr_17 1.0 el8.x86_64 pigsty 21.6 KiB imgsmlr_17-1.0-2PIGSTY.el8.x86_64.rpm
imgsmlr_17 1.0 el8.aarch64 pigsty 21.2 KiB imgsmlr_17-1.0-2PIGSTY.el8.aarch64.rpm
imgsmlr_17 1.0 el9.x86_64 pigsty 21.2 KiB imgsmlr_17-1.0-2PIGSTY.el9.x86_64.rpm
imgsmlr_17 1.0 el9.aarch64 pigsty 20.9 KiB imgsmlr_17-1.0-2PIGSTY.el9.aarch64.rpm
postgresql-17-imgsmlr 1.0 d12.x86_64 pigsty 30.9 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-imgsmlr 1.0 d12.aarch64 pigsty 30.2 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-imgsmlr 1.0 u22.x86_64 pigsty 34.0 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-imgsmlr 1.0 u22.aarch64 pigsty 33.3 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-imgsmlr 1.0 u24.x86_64 pigsty 32.3 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
postgresql-17-imgsmlr 1.0 u24.aarch64 pigsty 31.6 KiB postgresql-17-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
imgsmlr_16 1.0 el8.x86_64 pigsty 21.6 KiB imgsmlr_16-1.0-2PIGSTY.el8.x86_64.rpm
imgsmlr_16 1.0 el8.aarch64 pigsty 21.2 KiB imgsmlr_16-1.0-2PIGSTY.el8.aarch64.rpm
imgsmlr_16 1.0 el9.x86_64 pigsty 21.2 KiB imgsmlr_16-1.0-2PIGSTY.el9.x86_64.rpm
imgsmlr_16 1.0 el9.aarch64 pigsty 20.9 KiB imgsmlr_16-1.0-2PIGSTY.el9.aarch64.rpm
postgresql-16-imgsmlr 1.0 d12.x86_64 pigsty 30.9 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-imgsmlr 1.0 d12.aarch64 pigsty 30.2 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-imgsmlr 1.0 u22.x86_64 pigsty 34.0 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-imgsmlr 1.0 u22.aarch64 pigsty 33.3 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-imgsmlr 1.0 u24.x86_64 pigsty 32.3 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
postgresql-16-imgsmlr 1.0 u24.aarch64 pigsty 31.6 KiB postgresql-16-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
imgsmlr_15 1.0 el8.x86_64 pigsty 21.6 KiB imgsmlr_15-1.0-2PIGSTY.el8.x86_64.rpm
imgsmlr_15 1.0 el8.aarch64 pigsty 21.2 KiB imgsmlr_15-1.0-2PIGSTY.el8.aarch64.rpm
imgsmlr_15 1.0 el9.x86_64 pigsty 21.2 KiB imgsmlr_15-1.0-2PIGSTY.el9.x86_64.rpm
imgsmlr_15 1.0 el9.aarch64 pigsty 20.9 KiB imgsmlr_15-1.0-2PIGSTY.el9.aarch64.rpm
postgresql-15-imgsmlr 1.0 d12.x86_64 pigsty 30.9 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-imgsmlr 1.0 d12.aarch64 pigsty 30.2 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-imgsmlr 1.0 u22.x86_64 pigsty 34.1 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-imgsmlr 1.0 u22.aarch64 pigsty 33.4 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-imgsmlr 1.0 u24.x86_64 pigsty 32.3 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
postgresql-15-imgsmlr 1.0 u24.aarch64 pigsty 31.6 KiB postgresql-15-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
imgsmlr_14 1.0 el8.x86_64 pigsty 21.6 KiB imgsmlr_14-1.0-2PIGSTY.el8.x86_64.rpm
imgsmlr_14 1.0 el8.aarch64 pigsty 21.2 KiB imgsmlr_14-1.0-2PIGSTY.el8.aarch64.rpm
imgsmlr_14 1.0 el9.x86_64 pigsty 21.2 KiB imgsmlr_14-1.0-2PIGSTY.el9.x86_64.rpm
imgsmlr_14 1.0 el9.aarch64 pigsty 20.9 KiB imgsmlr_14-1.0-2PIGSTY.el9.aarch64.rpm
postgresql-14-imgsmlr 1.0 d12.x86_64 pigsty 30.9 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-imgsmlr 1.0 d12.aarch64 pigsty 30.2 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-imgsmlr 1.0 u22.x86_64 pigsty 34.1 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-imgsmlr 1.0 u22.aarch64 pigsty 33.3 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-imgsmlr 1.0 u24.x86_64 pigsty 32.3 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
postgresql-14-imgsmlr 1.0 u24.aarch64 pigsty 31.6 KiB postgresql-14-imgsmlr_1.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg imgsmlr;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install imgsmlr;		# install via package name, for the active PG version

pig install imgsmlr -v 18;   # install for PG 18
pig install imgsmlr -v 17;   # install for PG 17
pig install imgsmlr -v 16;   # install for PG 16
pig install imgsmlr -v 15;   # install for PG 15
pig install imgsmlr -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION imgsmlr;

Usage

imgsmlr: similar images search for PostgreSQL using Haar wavelet transform

The imgsmlr extension implements similar image searching functionality based on Haar wavelet transforms. It provides two data types and functions for converting images into searchable signatures.

CREATE EXTENSION imgsmlr;

Data Types

Datatype Storage Length Description
pattern 16388 bytes Result of Haar wavelet transform on the image
signature 64 bytes Short representation of pattern for fast GiST index searches

Functions

Function Return Type Description
jpeg2pattern(bytea) pattern Convert JPEG image data into pattern
png2pattern(bytea) pattern Convert PNG image data into pattern
gif2pattern(bytea) pattern Convert GIF image data into pattern
pattern2signature(pattern) signature Create signature from pattern
shuffle_pattern(pattern) pattern Shuffle pattern for less sensitivity to image shift

Operators

Operator Left Right Return Description
<-> pattern pattern float8 Euclidean distance between two patterns
<-> signature signature float8 Euclidean distance between two signatures

The signature type supports GiST indexing with KNN on the <-> operator.

Example

Create a table of patterns and signatures from JPEG images:

CREATE TABLE pat AS (
    SELECT
        id,
        shuffle_pattern(pattern) AS pattern,
        pattern2signature(pattern) AS signature
    FROM (
        SELECT id, jpeg2pattern(data) AS pattern
        FROM image
    ) x
);

ALTER TABLE pat ADD PRIMARY KEY (id);
CREATE INDEX pat_signature_idx ON pat USING gist (signature);

Search for the top 10 similar images to a given image:

SELECT id, smlr
FROM (
    SELECT
        id,
        pattern <-> (SELECT pattern FROM pat WHERE id = :id) AS smlr
    FROM pat
    WHERE id <> :id
    ORDER BY signature <-> (SELECT signature FROM pat WHERE id = :id)
    LIMIT 100
) x
ORDER BY x.smlr ASC
LIMIT 10;

The inner query selects the top 100 candidates by signature using the GiST index. The outer query refines to the top 10 by pattern distance.

Last updated on