visfeats 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+
8
+ jobs:
9
+ pre-commit:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.10"
17
+
18
+ - name: Run pre-commit
19
+ run: |
20
+ python -m pip install pre-commit
21
+ pre-commit run --all-files --show-diff-on-failure
22
+
23
+ pytest:
24
+ runs-on: ${{ matrix.os }}
25
+ strategy:
26
+ fail-fast: false
27
+ matrix:
28
+ os: [ubuntu-latest, windows-latest, macos-latest]
29
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
30
+
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ with:
34
+ fetch-depth: 0
35
+
36
+ - uses: actions/setup-python@v5
37
+ with:
38
+ python-version: ${{ matrix.python-version }}
39
+
40
+ - name: Install package
41
+ run: |
42
+ python -m pip install --upgrade pip
43
+ python -m pip install ".[dev]"
44
+
45
+ - name: Run pytest
46
+ run: python -m pytest
@@ -0,0 +1,67 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: "3.x"
30
+
31
+ - name: Build release distributions
32
+ run: |
33
+ # NOTE: put your own distribution build steps here.
34
+ python -m pip install build
35
+ python -m build
36
+
37
+ - name: Upload distributions
38
+ uses: actions/upload-artifact@v4
39
+ with:
40
+ name: release-dists
41
+ path: dist/
42
+
43
+ pypi-publish:
44
+ runs-on: ubuntu-latest
45
+ needs:
46
+ - release-build
47
+ permissions:
48
+ # IMPORTANT: this permission is mandatory for trusted publishing
49
+ id-token: write
50
+
51
+ # Dedicated environments with protections for publishing are strongly recommended.
52
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
53
+ environment:
54
+ name: pypi
55
+ url: https://pypi.org/p/VisFeats
56
+
57
+ steps:
58
+ - name: Retrieve release distributions
59
+ uses: actions/download-artifact@v4
60
+ with:
61
+ name: release-dists
62
+ path: dist/
63
+
64
+ - name: Publish release distributions to PyPI
65
+ uses: pypa/gh-action-pypi-publish@release/v1
66
+ with:
67
+ packages-dir: dist/
@@ -0,0 +1,187 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # Cursor
177
+ # Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
178
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
179
+ # refer to https://docs.cursor.com/context/ignore-files
180
+ .cursorignore
181
+ .cursorindexingignore
182
+
183
+ # AGENTS.md
184
+ AGENTS.md
185
+
186
+ # VS Code settings and workspace files
187
+ /.vscode
@@ -0,0 +1,5 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.8.6
4
+ hooks:
5
+ - id: ruff-format
visfeats-0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Qian Chu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
visfeats-0.1/PKG-INFO ADDED
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: visfeats
3
+ Version: 0.1
4
+ Summary: A library for extracting global visual features
5
+ Author-email: Qian Chu <qianchu99@gmail.com>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: scikit-image
10
+ Provides-Extra: resmem
11
+ Requires-Dist: resmem; extra == "resmem"
12
+ Provides-Extra: dev
13
+ Requires-Dist: resmem; extra == "dev"
14
+ Requires-Dist: pytest; extra == "dev"
15
+ Requires-Dist: pre-commit; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # VisFeats: Extraction of Global Visual Features from Images
19
+
20
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
21
+ ![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)
22
+
23
+ VisFeats is a library for extracting global visual features from images.
24
+
25
+ ## Installation
26
+
27
+ VisFeats is installable via PyPI:
28
+
29
+ ```bash
30
+ pip install visfeats
31
+ ```
32
+
33
+ Or via GitHub (for the latest development version):
34
+
35
+ ```bash
36
+ pip install git+https://github.com/ncc-brain/VisFeats.git
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ To use VisFeats, first load an image using PIL:
42
+
43
+ ```python
44
+ from PIL import Image
45
+ image = Image.open("path/to/your/image.jpg")
46
+ ```
47
+
48
+ All functions in VisFeats take a PIL ``Image.Image`` as input and return the corresponding feature values. Available features are described below.
49
+
50
+ ### Extract multiple features
51
+
52
+ Use `extract_all_features` to collect all package-level features, or pass a
53
+ feature name or list of names to select a subset. The result is a flat
54
+ dictionary.
55
+
56
+ ```python
57
+ from visfeats import extract_all_features
58
+
59
+ features = extract_all_features(image, features=["rms", "hsv_features"])
60
+ ```
61
+
62
+ ### Mean and entropy of HSV channels
63
+
64
+ Chromatic features describe color in HSV (Hue, Saturation, Value) space, including channel means and entropies. The `hsv_features` function returns a dictionary with six keys:
65
+
66
+ - `hue_mean`
67
+ - `saturation_mean`
68
+ - `value_mean`
69
+ - `hue_entropy`
70
+ - `saturation_entropy`
71
+ - `value_entropy`
72
+
73
+ ```python
74
+ from visfeats import hsv_features
75
+ features = hsv_features(image)
76
+ ```
77
+
78
+ ### Spatial frequency features
79
+
80
+ Spatial frequency features capture the distribution of different spatial frequencies in an image, which relate to the level of detail and texture. The `spatial_frequency_features` function extracts these features:
81
+
82
+ - `fourier_slope`
83
+ - `fourier_sigma`
84
+ - `dimensionality`
85
+ - `spectral_centroid`
86
+ - `spectral_variance`
87
+
88
+ ```python
89
+ from visfeats import spatial_frequency_features
90
+ features = spatial_frequency_features(image)
91
+ ```
92
+
93
+ ### Memorability
94
+
95
+ While memorability is often considered a subjective property, recent research has shown that it can be predicted from image content. Here the `memorability_resmem` function estimates intrinsic memorability using the pretrained ResMem model described by [Needell and Bainbridge (2022)](https://doi.org/10.1007/s42113-022-00126-5).
96
+
97
+ ResMem is an optional dependency. It can be installed along with VisFeats using:
98
+
99
+ ```bash
100
+ pip install "visfeats[resmem]"
101
+ ```
102
+
103
+ Or separately with:
104
+
105
+ ```bash
106
+ pip install resmem
107
+ ```
108
+
109
+ Then you can use the `memorability_resmem` function to estimate the memorability of an image:
110
+
111
+ ```python
112
+ from visfeats import memorability_resmem
113
+ resmem_score = memorability_resmem(image)
114
+ ```
115
+
116
+ ### Other features
117
+
118
+ #### RMS contrast
119
+
120
+ The `rms` function computes the root-mean-square contrast as the population standard deviation of the image's grayscale pixel intensities.
121
+
122
+ ```python
123
+ from visfeats import rms
124
+ rms_contrast = rms(image)
125
+ ```
visfeats-0.1/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # VisFeats: Extraction of Global Visual Features from Images
2
+
3
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
4
+ ![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)
5
+
6
+ VisFeats is a library for extracting global visual features from images.
7
+
8
+ ## Installation
9
+
10
+ VisFeats is installable via PyPI:
11
+
12
+ ```bash
13
+ pip install visfeats
14
+ ```
15
+
16
+ Or via GitHub (for the latest development version):
17
+
18
+ ```bash
19
+ pip install git+https://github.com/ncc-brain/VisFeats.git
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ To use VisFeats, first load an image using PIL:
25
+
26
+ ```python
27
+ from PIL import Image
28
+ image = Image.open("path/to/your/image.jpg")
29
+ ```
30
+
31
+ All functions in VisFeats take a PIL ``Image.Image`` as input and return the corresponding feature values. Available features are described below.
32
+
33
+ ### Extract multiple features
34
+
35
+ Use `extract_all_features` to collect all package-level features, or pass a
36
+ feature name or list of names to select a subset. The result is a flat
37
+ dictionary.
38
+
39
+ ```python
40
+ from visfeats import extract_all_features
41
+
42
+ features = extract_all_features(image, features=["rms", "hsv_features"])
43
+ ```
44
+
45
+ ### Mean and entropy of HSV channels
46
+
47
+ Chromatic features describe color in HSV (Hue, Saturation, Value) space, including channel means and entropies. The `hsv_features` function returns a dictionary with six keys:
48
+
49
+ - `hue_mean`
50
+ - `saturation_mean`
51
+ - `value_mean`
52
+ - `hue_entropy`
53
+ - `saturation_entropy`
54
+ - `value_entropy`
55
+
56
+ ```python
57
+ from visfeats import hsv_features
58
+ features = hsv_features(image)
59
+ ```
60
+
61
+ ### Spatial frequency features
62
+
63
+ Spatial frequency features capture the distribution of different spatial frequencies in an image, which relate to the level of detail and texture. The `spatial_frequency_features` function extracts these features:
64
+
65
+ - `fourier_slope`
66
+ - `fourier_sigma`
67
+ - `dimensionality`
68
+ - `spectral_centroid`
69
+ - `spectral_variance`
70
+
71
+ ```python
72
+ from visfeats import spatial_frequency_features
73
+ features = spatial_frequency_features(image)
74
+ ```
75
+
76
+ ### Memorability
77
+
78
+ While memorability is often considered a subjective property, recent research has shown that it can be predicted from image content. Here the `memorability_resmem` function estimates intrinsic memorability using the pretrained ResMem model described by [Needell and Bainbridge (2022)](https://doi.org/10.1007/s42113-022-00126-5).
79
+
80
+ ResMem is an optional dependency. It can be installed along with VisFeats using:
81
+
82
+ ```bash
83
+ pip install "visfeats[resmem]"
84
+ ```
85
+
86
+ Or separately with:
87
+
88
+ ```bash
89
+ pip install resmem
90
+ ```
91
+
92
+ Then you can use the `memorability_resmem` function to estimate the memorability of an image:
93
+
94
+ ```python
95
+ from visfeats import memorability_resmem
96
+ resmem_score = memorability_resmem(image)
97
+ ```
98
+
99
+ ### Other features
100
+
101
+ #### RMS contrast
102
+
103
+ The `rms` function computes the root-mean-square contrast as the population standard deviation of the image's grayscale pixel intensities.
104
+
105
+ ```python
106
+ from visfeats import rms
107
+ rms_contrast = rms(image)
108
+ ```
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=80", "setuptools-scm>=8"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "visfeats"
7
+ dynamic = ["version"]
8
+ description = "A library for extracting global visual features"
9
+ readme = "README.md"
10
+ authors = [{ name = "Qian Chu", email = "qianchu99@gmail.com" }]
11
+ requires-python = ">=3.10"
12
+ dependencies = ["scikit-image"]
13
+
14
+ [project.optional-dependencies]
15
+ resmem = ["resmem"]
16
+ dev = ["resmem", "pytest", "pre-commit"]
17
+
18
+ [tool.setuptools.packages.find]
19
+ where = ["src"]
20
+
21
+ [tool.setuptools_scm]
22
+ local_scheme = "node-and-date"
visfeats-0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,85 @@
1
+ import logging
2
+ from collections.abc import Sequence
3
+ from importlib.util import find_spec
4
+ from typing import Dict, Union
5
+
6
+ from PIL import Image
7
+
8
+ from .chromatic import hsv_features
9
+ from .spatial_frequency import spatial_frequency_features
10
+ from .memorability import memorability_resmem
11
+ from .misc import rms
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ _FEATURES = {
16
+ "hsv_features": hsv_features,
17
+ "spatial_frequency_features": spatial_frequency_features,
18
+ "rms": rms,
19
+ "memorability_resmem": memorability_resmem,
20
+ }
21
+
22
+ __all__ = [
23
+ "extract_all_features",
24
+ "spatial_frequency_features",
25
+ "hsv_features",
26
+ "rms",
27
+ "memorability_resmem",
28
+ ]
29
+
30
+
31
+ def extract_all_features(
32
+ image: Image.Image,
33
+ features: Union[str, Sequence[str]] = "all",
34
+ ) -> Dict[str, float]:
35
+ """Extract selected visual features from an image.
36
+
37
+ Parameters
38
+ ----------
39
+ image : PIL.Image.Image
40
+ Input image in any Pillow mode.
41
+ features : str or sequence of str, default="all"
42
+ ``"all"`` selects every package-level feature. A feature name or
43
+ sequence of feature names selects only those features. Available
44
+ names are ``"hsv_features"``, ``"spatial_frequency_features"``,
45
+ ``"rms"``, and ``"memorability_resmem"``.
46
+
47
+ Returns
48
+ -------
49
+ dict of {str: float}
50
+ A flat mapping of feature names to values. Multi-value features
51
+ contribute their own keys. ``memorability_resmem`` is skipped with a
52
+ warning if the optional ``resmem`` package is not installed.
53
+
54
+ Raises
55
+ ------
56
+ ValueError
57
+ If any requested feature name is not available.
58
+ """
59
+ if isinstance(features, str):
60
+ selected = list(_FEATURES) if features == "all" else [features]
61
+ else:
62
+ selected = list(dict.fromkeys(features))
63
+
64
+ unknown = set(selected) - _FEATURES.keys()
65
+ if unknown:
66
+ names = ", ".join(sorted(unknown))
67
+ raise ValueError(f"Unknown feature name(s): {names}")
68
+
69
+ extracted: Dict[str, float] = {}
70
+ for name in selected:
71
+ if name == "memorability_resmem" and find_spec("resmem") is None:
72
+ logger.warning(
73
+ "Skipping memorability_resmem because the optional `resmem` "
74
+ "package is not installed. Install it with: "
75
+ "pip install 'visfeats[resmem]'"
76
+ )
77
+ continue
78
+
79
+ result = _FEATURES[name](image)
80
+ if isinstance(result, dict):
81
+ extracted.update(result)
82
+ else:
83
+ extracted[name] = float(result)
84
+
85
+ return extracted