imgsmlr
使用Haar小波分析计算图片相似度
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
imgsmlr | 1.0 | FEAT | PostgreSQL | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 2830 | imgsmlr | 否 | 是 | 否 | 是 | 否 | 是 | - |
| 相关扩展 | age hll rum pg_graphql pg_jsonschema jsquery pg_hint_plan hypopg |
|---|
breaks on el10
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | imgsmlr | - |
| RPM | PIGSTY | 1.0 | 1817161514 | imgsmlr_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-imgsmlr | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0 el8.x86_64.pg18 : imgsmlr_18 imgsmlr_18-1.0-2PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0 el8.x86_64.pg17 : imgsmlr_17 imgsmlr_17-1.0-2PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0 el8.x86_64.pg16 : imgsmlr_16 imgsmlr_16-1.0-2PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0 el8.x86_64.pg15 : imgsmlr_15 imgsmlr_15-1.0-2PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0 el8.x86_64.pg14 : imgsmlr_14 imgsmlr_14-1.0-2PIGSTY.el8.x86_64.rpm
|
| el8.aarch64 | PIGSTY 1.0 el8.aarch64.pg18 : imgsmlr_18 imgsmlr_18-1.0-2PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0 el8.aarch64.pg17 : imgsmlr_17 imgsmlr_17-1.0-2PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0 el8.aarch64.pg16 : imgsmlr_16 imgsmlr_16-1.0-2PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0 el8.aarch64.pg15 : imgsmlr_15 imgsmlr_15-1.0-2PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0 el8.aarch64.pg14 : imgsmlr_14 imgsmlr_14-1.0-2PIGSTY.el8.aarch64.rpm
|
| el9.x86_64 | PIGSTY 1.0 el9.x86_64.pg18 : imgsmlr_18 imgsmlr_18-1.0-2PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0 el9.x86_64.pg17 : imgsmlr_17 imgsmlr_17-1.0-2PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0 el9.x86_64.pg16 : imgsmlr_16 imgsmlr_16-1.0-2PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0 el9.x86_64.pg15 : imgsmlr_15 imgsmlr_15-1.0-2PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0 el9.x86_64.pg14 : imgsmlr_14 imgsmlr_14-1.0-2PIGSTY.el9.x86_64.rpm
|
| el9.aarch64 | PIGSTY 1.0 el9.aarch64.pg18 : imgsmlr_18 imgsmlr_18-1.0-2PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0 el9.aarch64.pg17 : imgsmlr_17 imgsmlr_17-1.0-2PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0 el9.aarch64.pg16 : imgsmlr_16 imgsmlr_16-1.0-2PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0 el9.aarch64.pg15 : imgsmlr_15 imgsmlr_15-1.0-2PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0 el9.aarch64.pg14 : imgsmlr_14 imgsmlr_14-1.0-2PIGSTY.el9.aarch64.rpm
|
| el10.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 1.0 d12.x86_64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0 d12.x86_64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0 d12.x86_64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0 d12.x86_64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0 d12.x86_64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY 1.0 d12.aarch64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0 d12.aarch64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0 d12.aarch64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0 d12.aarch64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0 d12.aarch64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 1.0 u22.x86_64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.0 u22.x86_64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.0 u22.x86_64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.0 u22.x86_64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 1.0 u22.x86_64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY 1.0 u22.aarch64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.0 u22.aarch64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.0 u22.aarch64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.0 u22.aarch64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 1.0 u22.aarch64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY 1.0 u24.x86_64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.0 u24.x86_64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.0 u24.x86_64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.0 u24.x86_64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
| PIGSTY 1.0 u24.x86_64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY 1.0 u24.aarch64.pg18 : postgresql-18-imgsmlr postgresql-18-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.0 u24.aarch64.pg17 : postgresql-17-imgsmlr postgresql-17-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.0 u24.aarch64.pg16 : postgresql-16-imgsmlr postgresql-16-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.0 u24.aarch64.pg15 : postgresql-15-imgsmlr postgresql-15-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
| PIGSTY 1.0 u24.aarch64.pg14 : postgresql-14-imgsmlr postgresql-14-imgsmlr_1.0-1PIGSTY~noble_arm64.deb
|
构建
您可以使用 pig build 命令构建 imgsmlr 扩展的 RPM / DEB 包:
pig build pkg imgsmlr # 构建 RPM / DEB 包
安装
您可以直接安装 imgsmlr 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install imgsmlr; # 当前活跃 PG 版本安装
pig ext install -y imgsmlr -v 18 # PG 18
pig ext install -y imgsmlr -v 17 # PG 17
pig ext install -y imgsmlr -v 16 # PG 16
pig ext install -y imgsmlr -v 15 # PG 15
pig ext install -y imgsmlr -v 14 # PG 14
dnf install -y imgsmlr_18 # PG 18
dnf install -y imgsmlr_17 # PG 17
dnf install -y imgsmlr_16 # PG 16
dnf install -y imgsmlr_15 # PG 15
dnf install -y imgsmlr_14 # PG 14
apt install -y postgresql-18-imgsmlr # PG 18
apt install -y postgresql-17-imgsmlr # PG 17
apt install -y postgresql-16-imgsmlr # PG 16
apt install -y postgresql-15-imgsmlr # PG 15
apt install -y postgresql-14-imgsmlr # PG 14
创建扩展:
CREATE EXTENSION imgsmlr;
用法
imgsmlr 扩展基于 Haar 小波变换实现了相似图片搜索功能。它提供了两种数据类型和用于将图片转换为可搜索签名的函数。
CREATE EXTENSION imgsmlr;
数据类型
| 数据类型 | 存储长度 | 描述 |
|---|---|---|
pattern | 16388 字节 | 图片的 Haar 小波变换结果 |
signature | 64 字节 | 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 以降低对图片位移的敏感度 |
运算符
| 运算符 | 左操作数 | 右操作数 | 返回类型 | 描述 |
|---|---|---|---|---|
<-> | pattern | pattern | float8 | 两个 pattern 之间的欧氏距离 |
<-> | signature | signature | float8 | 两个 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 个。