Gradient Naturalization for image quality assessment
Project description
GraNatPy - Gradient Naturalization for Image Enhancement and Evaluation
This is a Python implementation of the paper:
Y. Gong and I. F. Sbalzarini. A natural-scene gradient distribution prior and its application in light-microscopy image processing. IEEE Journal of Selected Topics in Signal Processing, 10(1):99–114, 2016.
The original code can be found here.
In short, Naturalness is a gradient-based metric that can be computed for an arbitrary image; Naturalization is the method that can enhance images based on this metric.
The Naturalness metric reflects the similarity in the gradient distribution of a sample image to a gradient distribution learned from large image datasets. The closer the Naturalness is to 1, the closer the image is to what we perceive as natural. This is useful for evaluating the perceived quality of synthetically created images.
From their abstract:
[...] We argue here that the gradient distribution of natural-scene images may provide a versatile and well-founded prior for light-microscopy images that does not impose assumptions about the geometry of the ground-truth signal, but only about its gradient spectrum. We provide motivation for this choice from different points of view, and we illustrate the resulting regularizer for use on light-microscopy images. We provide a simple parametric model for the resulting prior, leading to efficiently solvable variational problems. We demonstrate the use of these models and solvers in a variety of common image-processing tasks, including contrast enhancement, noise-level estimation, denoising, blind deconvolution, and dehazing. [...]
The GraNatPy package contains the following classes and functions:
GraNat: convenience class wrapping the full pipeline: loading, naturalization, visualization and savingnaturalize_rgb_image: core function to naturalize an RGB or grayscale imagenaturalize_single_channel: core function to naturalize a single image channelcompute_all_metrics: compute and print the dNf (delta Naturalness factor), MSE, PSNR, SSIM and NRMSE between two imagescompare_images: compare a reference image against a set of similar (e.g., synthetic) images and print a summaryoverlay_naturalness_heatmap: visualize per-region naturalness as a heatmap overlay on the original image
Installation
The simplest way is to install the package via pip:
pip install granatpy
Alternatively, clone the repository and install in editable mode:
git clone https://github.com/casus/GraNatPy
cd granatpy
pip install -e .
Quick Start
from granatpy import GraNat
# Load, naturalize and save
GraNat.load_image("photo.tif").naturalize(show=True).save("output.png")
# Visualize naturalness heatmap
from granatpy import overlay_naturalness_heatmap
import imageio.v3 as imageio
import numpy as np
img = imageio.imread("photo.tif")
fig, ax, heatmap = overlay_naturalness_heatmap(img, grid_rows=20, grid_cols=30)
# Compare images
from granatpy import compare_images
images = {
"photo_low.tif",
"photo_high.tif",
}
real = "photo_real.tif"
results = compare_images(real, images)
You can also find an example notebook in example/example.ipynb
License
This project is licensed under the GPL-3.0 License. See LICENSE for details.
For attribution of example images, see ATTRIBUTION.md.
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 granatpy-0.1.0.tar.gz.
File metadata
- Download URL: granatpy-0.1.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6af34a1c386137ea9197d6da7e270f35a20a42bcfced32da035c38dc9c71e3
|
|
| MD5 |
56ea3b1919456d1641045b02f7c15e57
|
|
| BLAKE2b-256 |
972399589831e88b4327910f205a90a0410b6436f22bb79aca36b5f86ab063c6
|
Provenance
The following attestation bundles were made for granatpy-0.1.0.tar.gz:
Publisher:
python-publish.yml on casus/GraNatPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
granatpy-0.1.0.tar.gz -
Subject digest:
1c6af34a1c386137ea9197d6da7e270f35a20a42bcfced32da035c38dc9c71e3 - Sigstore transparency entry: 1174609742
- Sigstore integration time:
-
Permalink:
casus/GraNatPy@27a67691fc780d9c94cb56bd2185c89c65cdce8c -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/casus
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@27a67691fc780d9c94cb56bd2185c89c65cdce8c -
Trigger Event:
release
-
Statement type:
File details
Details for the file granatpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: granatpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e106ec8d8c68c538d45ba9700e1f99a3ad2ca116e960f9df2d192e26d2f4fc8
|
|
| MD5 |
943ccc945800312039faf03f765840c2
|
|
| BLAKE2b-256 |
b16bea722c9f993370f365e54ad986e800914a63f4e3f847fce1453b3db5f1f6
|
Provenance
The following attestation bundles were made for granatpy-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on casus/GraNatPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
granatpy-0.1.0-py3-none-any.whl -
Subject digest:
2e106ec8d8c68c538d45ba9700e1f99a3ad2ca116e960f9df2d192e26d2f4fc8 - Sigstore transparency entry: 1174609767
- Sigstore integration time:
-
Permalink:
casus/GraNatPy@27a67691fc780d9c94cb56bd2185c89c65cdce8c -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/casus
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@27a67691fc780d9c94cb56bd2185c89c65cdce8c -
Trigger Event:
release
-
Statement type: