NightFocus
What it is
Simple python package for automated focus optimization of astrophotography image patches.
How to use it
- create a sublcass of Camera for your camera. It must implement the take_picture method:
from nightfocus.camera import Camera
class MyCamera(Camera):
def take_picture(self, focus: int) -> np.ndarray:
raise NotImplementedError
- perform focus optimization:
from nightfocus import optimize_focus
best_focus, _ = optimize_focus(camera, bounds=(0, 100))
Under the hood
NightFocus uses Bayesian optimization to find the best focus position. The default metric used is the tenengrad focus measure:
def tenengrad(image: np.ndarray, ksize: int = 3) -> float:
"""
Tenengrad focus measure based on gradient magnitude.
Works well for star images and is computationally efficient.
"""
if len(image.shape) == 3:
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
else:
gray = image
gx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=ksize)
gy = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=ksize)
return float(np.mean(gx**2 + gy**2))
Other metrics are available in the nightfocus.focus_metrics module:
from nightfocus.focus_metrics import FOCUS_MEASURES
FOCUS_MEASURES = {
"tenengrad": tenengrad,
"modified_laplacian": modified_laplacian,
"normalized_variance": normalized_variance,
"spectral_energy": spectral_energy,
"brenner_gradient": brenner_gradient,
"threshold_count": threshold_count,
"fast_entropy": fast_entropy,
"wavelet_measure": wavelet_measure,
}
How we know it works
It could find the correct focus when running on the datasets located in the images folder. A dataset file corresponds to a corresponding tiff image on which increasing values of blur where applied.
Command Line Interface
NightFocus includes a CLI for common tasks:
nightfocus --help
It provides this commands:
- crops: Create random crops from an image.
- dataset: Generate blurred dataset from TIFF files with increasing blur.
- evaluate: Evaluate focus scoring on a dataset.
- evaluate-directory: Evaluate focus scoring on a directory of images.
- evaluate-metrics: Evaluate multiple focus metrics on a dataset and print results.
- view: View images from a dataset file with their focus values.
Installation
pip install nightfocus
Author
Vincent Berenz, Max Planck Institute for Intelligent Systems, Tuebingen, Germany
Metadata
Release files for nightfocus 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| nightfocus-0.1.3.tar.gz | 20.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nightfocus-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.4 kB
Release files / nightfocus-0.1.3.tar.gz
| Download URL | nightfocus-0.1.3.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c66eb8a9ab96dae08cf81d8d940528f7c36729ef3bea5e6b8f09e509b31913a
|
|
BLAKE2b-256 checksum How to use checksums |
e0a61bcd875fb66bc9cfc5a57e16c066ac0cebaaae97e6fa2e3d22f7a6e66862
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.12.3 Linux/6.8.0-59-generic
|
Release files / nightfocus-0.1.3-py3-none-any.whl
| Download URL | nightfocus-0.1.3-py3-none-any.whl |
|---|---|
| Size | 25.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21ff0d358407160cdb6ac4ddeee676b124365b464194a4c42036726589337eeb
|
|
BLAKE2b-256 checksum How to use checksums |
d18ac71657f62cb73131ff2499ceba9eb8a4f416a87bc1ca77da251366fc5c32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.12.3 Linux/6.8.0-59-generic
|
Security for nightfocus 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.