跳转到主要内容

imgsmlr

使用Haar小波分析计算图片相似度

imgsmlr · 使用Haar小波分析计算图片相似度

概览

ID扩展软件包版本类别许可证编程语言
2830imgsmlrimgsmlr1.0FEATPostgreSQLC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
breaks on el10

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.019 18 17 16 15imgsmlr-
RPMPIGSTY1.0.019 18 17 16 15imgsmlr_$v-
DEBPIGSTY1.0.019 18 17 16 15postgresql-$v-imgsmlr-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el8.aarch64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el9.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el10.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el10.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d12.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d12.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d13.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d13.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u22.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u22.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u24.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u24.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u26.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u26.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
软件包版本平台仓库大小下载
imgsmlr_191.0.0el9.x86_64pigsty40.0 KiBimgsmlr_19-1.0.0-1PGSTY.el9.x86_64.rpm
imgsmlr_191.0.0el9.aarch64pigsty39.7 KiBimgsmlr_19-1.0.0-1PGSTY.el9.aarch64.rpm
imgsmlr_191.0.0el10.x86_64pigsty40.0 KiBimgsmlr_19-1.0.0-1PGSTY.el10.x86_64.rpm
imgsmlr_191.0.0el10.aarch64pigsty39.7 KiBimgsmlr_19-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-19-imgsmlr1.0.0d12.x86_64pigsty31.3 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-19-imgsmlr1.0.0d12.aarch64pigsty30.6 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-19-imgsmlr1.0.0d13.x86_64pigsty31.2 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-19-imgsmlr1.0.0d13.aarch64pigsty30.6 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-19-imgsmlr1.0.0u22.x86_64pigsty33.2 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-19-imgsmlr1.0.0u22.aarch64pigsty32.4 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-19-imgsmlr1.0.0u24.x86_64pigsty32.7 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~noble_amd64.deb
postgresql-19-imgsmlr1.0.0u24.aarch64pigsty32.0 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~noble_arm64.deb
postgresql-19-imgsmlr1.0.0u26.x86_64pigsty32.9 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-19-imgsmlr1.0.0u26.aarch64pigsty32.0 KiBpostgresql-19-imgsmlr_1.0.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
imgsmlr_181.0el8.x86_64pigsty39.0 KiBimgsmlr_18-1.0-2.git20180223.c484a15PGSTY.el8.x86_64.rpm
imgsmlr_181.0el8.aarch64pigsty39.1 KiBimgsmlr_18-1.0-2.git20180223.c484a15PGSTY.el8.aarch64.rpm
imgsmlr_181.0.0el9.x86_64pigsty40.1 KiBimgsmlr_18-1.0.0-1PGSTY.el9.x86_64.rpm
imgsmlr_181.0.0el9.aarch64pigsty39.8 KiBimgsmlr_18-1.0.0-1PGSTY.el9.aarch64.rpm
imgsmlr_181.0.0el10.x86_64pigsty40.1 KiBimgsmlr_18-1.0.0-1PGSTY.el10.x86_64.rpm
imgsmlr_181.0.0el10.aarch64pigsty39.8 KiBimgsmlr_18-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-18-imgsmlr1.0.0d12.x86_64pigsty31.2 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-18-imgsmlr1.0.0d12.aarch64pigsty30.5 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-18-imgsmlr1.0.0d13.x86_64pigsty31.1 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-18-imgsmlr1.0.0d13.aarch64pigsty30.5 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-18-imgsmlr1.0.0u22.x86_64pigsty33.2 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-18-imgsmlr1.0.0u22.aarch64pigsty32.5 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-18-imgsmlr1.0.0u24.x86_64pigsty32.6 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~noble_amd64.deb
postgresql-18-imgsmlr1.0.0u24.aarch64pigsty31.9 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~noble_arm64.deb
postgresql-18-imgsmlr1.0.0u26.x86_64pigsty33.0 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-18-imgsmlr1.0.0u26.aarch64pigsty32.2 KiBpostgresql-18-imgsmlr_1.0.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
imgsmlr_171.0el8.x86_64pigsty38.9 KiBimgsmlr_17-1.0-2.git20180223.c484a15PGSTY.el8.x86_64.rpm
imgsmlr_171.0el8.aarch64pigsty39.1 KiBimgsmlr_17-1.0-2.git20180223.c484a15PGSTY.el8.aarch64.rpm
imgsmlr_171.0.0el9.x86_64pigsty40.1 KiBimgsmlr_17-1.0.0-1PGSTY.el9.x86_64.rpm
imgsmlr_171.0.0el9.aarch64pigsty39.8 KiBimgsmlr_17-1.0.0-1PGSTY.el9.aarch64.rpm
imgsmlr_171.0.0el10.x86_64pigsty40.1 KiBimgsmlr_17-1.0.0-1PGSTY.el10.x86_64.rpm
imgsmlr_171.0.0el10.aarch64pigsty39.7 KiBimgsmlr_17-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-17-imgsmlr1.0.0d12.x86_64pigsty31.2 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-17-imgsmlr1.0.0d12.aarch64pigsty30.5 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-17-imgsmlr1.0.0d13.x86_64pigsty31.1 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-17-imgsmlr1.0.0d13.aarch64pigsty30.5 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-17-imgsmlr1.0.0u22.x86_64pigsty34.4 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-17-imgsmlr1.0.0u22.aarch64pigsty33.6 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-17-imgsmlr1.0.0u24.x86_64pigsty32.6 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~noble_amd64.deb
postgresql-17-imgsmlr1.0.0u24.aarch64pigsty31.9 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~noble_arm64.deb
postgresql-17-imgsmlr1.0.0u26.x86_64pigsty33.0 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-17-imgsmlr1.0.0u26.aarch64pigsty32.2 KiBpostgresql-17-imgsmlr_1.0.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
imgsmlr_161.0el8.x86_64pigsty38.9 KiBimgsmlr_16-1.0-2.git20180223.c484a15PGSTY.el8.x86_64.rpm
imgsmlr_161.0el8.aarch64pigsty39.1 KiBimgsmlr_16-1.0-2.git20180223.c484a15PGSTY.el8.aarch64.rpm
imgsmlr_161.0.0el9.x86_64pigsty40.1 KiBimgsmlr_16-1.0.0-1PGSTY.el9.x86_64.rpm
imgsmlr_161.0.0el9.aarch64pigsty39.7 KiBimgsmlr_16-1.0.0-1PGSTY.el9.aarch64.rpm
imgsmlr_161.0.0el10.x86_64pigsty40.1 KiBimgsmlr_16-1.0.0-1PGSTY.el10.x86_64.rpm
imgsmlr_161.0.0el10.aarch64pigsty39.8 KiBimgsmlr_16-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-16-imgsmlr1.0.0d12.x86_64pigsty31.2 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-16-imgsmlr1.0.0d12.aarch64pigsty30.5 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-16-imgsmlr1.0.0d13.x86_64pigsty31.1 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-16-imgsmlr1.0.0d13.aarch64pigsty30.5 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-16-imgsmlr1.0.0u22.x86_64pigsty34.4 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-16-imgsmlr1.0.0u22.aarch64pigsty33.6 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-16-imgsmlr1.0.0u24.x86_64pigsty32.6 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~noble_amd64.deb
postgresql-16-imgsmlr1.0.0u24.aarch64pigsty31.9 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~noble_arm64.deb
postgresql-16-imgsmlr1.0.0u26.x86_64pigsty33.0 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-16-imgsmlr1.0.0u26.aarch64pigsty32.2 KiBpostgresql-16-imgsmlr_1.0.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
imgsmlr_151.0el8.x86_64pigsty38.9 KiBimgsmlr_15-1.0-2.git20180223.c484a15PGSTY.el8.x86_64.rpm
imgsmlr_151.0el8.aarch64pigsty39.1 KiBimgsmlr_15-1.0-2.git20180223.c484a15PGSTY.el8.aarch64.rpm
imgsmlr_151.0.0el9.x86_64pigsty40.1 KiBimgsmlr_15-1.0.0-1PGSTY.el9.x86_64.rpm
imgsmlr_151.0.0el9.aarch64pigsty39.8 KiBimgsmlr_15-1.0.0-1PGSTY.el9.aarch64.rpm
imgsmlr_151.0.0el10.x86_64pigsty40.1 KiBimgsmlr_15-1.0.0-1PGSTY.el10.x86_64.rpm
imgsmlr_151.0.0el10.aarch64pigsty39.8 KiBimgsmlr_15-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-15-imgsmlr1.0.0d12.x86_64pigsty31.2 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-15-imgsmlr1.0.0d12.aarch64pigsty30.5 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-15-imgsmlr1.0.0d13.x86_64pigsty31.2 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-15-imgsmlr1.0.0d13.aarch64pigsty30.6 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-15-imgsmlr1.0.0u22.x86_64pigsty34.5 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-15-imgsmlr1.0.0u22.aarch64pigsty33.7 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-15-imgsmlr1.0.0u24.x86_64pigsty32.6 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~noble_amd64.deb
postgresql-15-imgsmlr1.0.0u24.aarch64pigsty32.0 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~noble_arm64.deb
postgresql-15-imgsmlr1.0.0u26.x86_64pigsty33.1 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-15-imgsmlr1.0.0u26.aarch64pigsty32.2 KiBpostgresql-15-imgsmlr_1.0.0-1PGSTY~resolute_arm64.deb

源码

imgsmlr-1.0+git20180223.c484a15.tar.gz

pig build pkg imgsmlr;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install imgsmlr;		# install by package name

pig install imgsmlr -v 19;   # install for PG 19
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

在数据库中创建扩展。

CREATE EXTENSION imgsmlr;

用法

imgsmlr: 使用 Haar 小波变换实现 PostgreSQL 相似图片搜索

imgsmlr 扩展基于 Haar 小波变换实现了相似图片搜索功能。它提供了两种数据类型和用于将图片转换为可搜索签名的函数。

CREATE EXTENSION imgsmlr;

数据类型

数据类型存储长度描述
pattern16388 字节图片的 Haar 小波变换结果
signature64 字节pattern 的短表示,用于快速 GiST 索引搜索

函数

函数返回类型描述
jpeg2pattern(bytea)pattern将 JPEG 图片数据转换为 pattern
png2pattern(bytea)pattern将 PNG 图片数据转换为 pattern
gif2pattern(bytea)pattern将 GIF 图片数据转换为 pattern
pattern2signature(pattern)signature从 pattern 创建 signature
shuffle_pattern(pattern)pattern打乱 pattern 以降低对图片位移的敏感度

运算符

运算符左操作数右操作数返回类型描述
<->patternpatternfloat8两个 pattern 之间的欧氏距离
<->signaturesignaturefloat8两个 signature 之间的欧氏距离

signature 类型支持基于 <-> 运算符的 GiST KNN 索引。

示例

从 JPEG 图片创建 pattern 和 signature 表:

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);

搜索与给定图片最相似的前 10 张图片:

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;

内层查询利用 GiST 索引按 signature 选出前 100 个候选项,外层查询按 pattern 距离精炼到前 10 个。

表格阅读器