Implement the feature extraction function of the ``imgsmlr`` extension for ``PostgreSQL``.
Project description
libimgsmlr
Implement the feature extraction function of the imgsmlr extension, in languages such as: c(so file), Python. Other languages should probably call dynamic libraries to adapt.
When using the PostgreSQL extension imgsmlr, I found that the feature extraction functions provided by imgsmlr are all PostgreSQL functions. This poses a problem, as the files need to be uploaded to and stored in the database during testing. This is generally not possible in service development, where text is usually stored separately in the file system, and only paths and pattern, signature are stored in the database. Therefore, it is necessary to implement the feature extraction functions used by the service development language.
Depends
This library depends on the gd library. Please install it yourself first.
On Mac OSX: brew install gd
On Linux: yum install -y gd-devel
Installation
pip install --global-option=build_ext libimgsmlr
Errors
If the following error is encountered on Mac OSX.
fatal error: 'gd.h' file not found #include "gd.h"
The solution is to set the environment variable first:
export CFLAGS="-I$(brew --prefix gd)/include" export LFDLAGS="-L$(brew --prefix gd)/lib"
Examples
import argparse
from libimgsmlr import img2pattern, pattern2signature, shuffle_pattern, pattern_distance, signature_distance
def image_pattern_signature(content):
pattern = img2pattern(content)
signature = pattern2signature(pattern)
pattern = shuffle_pattern(pattern)
return pattern, signature
def process_single_image(filename):
content = open(filename, "rb").read()
try:
pattern, signature = image_pattern_signature(content)
print(f"pattern: {pattern.as_array()}")
print(f"signature: {signature}")
except ValueError as err:
print(f"Error: img2pattern({filename}) failed! {err}")
def calculate_distance(filename1, filename2):
try:
content1 = open(filename1, "rb").read()
content2 = open(filename2, "rb").read()
pattern1, signature1 = image_pattern_signature(content1)
pattern2, signature2 = image_pattern_signature(content2)
pattern_dist = pattern_distance(pattern1, pattern2)
print(f"Pattern distance: {pattern_dist}")
sig_dist = signature_distance(signature1, signature2)
print(f"Signature distance: {sig_dist}")
except ValueError as err:
print(f"Error: Failed to calculate distance! {err}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="libimgsmlr test")
parser.add_argument('filenames', nargs='+', help='Image files (jpeg/png/gif)')
args = parser.parse_args()
if len(args.filenames) == 1:
process_single_image(args.filenames[0])
elif len(args.filenames) == 2:
calculate_distance(args.filenames[0], args.filenames[1])
else:
print("Please provide 1 or 2 image filenames")
LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libimgsmlr-0.1.6.tar.gz.
File metadata
- Download URL: libimgsmlr-0.1.6.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ec0ef19264eef778e31a3bd950e5531fc04488cbf9b32e7430e3943b1c9bc70
|
|
| MD5 |
0a045ecff123db3ecae1da944e164aef
|
|
| BLAKE2b-256 |
402d947763798d9b052442038e9c307cd901146c6068c1fc49bdc6b00fd524c4
|
File details
Details for the file libimgsmlr-0.1.6-py3-none-any.whl.
File metadata
- Download URL: libimgsmlr-0.1.6-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0e0b1d0587c6dd66079d04eda50801a4c8fbe762f6028f216d59c0fca517719
|
|
| MD5 |
dec2dbec12c7d42f7d8c77232dffaf47
|
|
| BLAKE2b-256 |
683e33f9156861b2414858032aa3a650ba87ee0a54ca951113701eace423067d
|