Tools and functions for 4x4 Mueller matrices
Project description
Tools for Mueller Matrices
A collection of functions to manipulate and process Mueller matrix data.
This package provides tools for two primary tasks:
- Physical Realizability Test
- Decomposition
Both modules have been adapted to work with single 4×4 Mueller matrices as well as with Mueller matrix images (e.g. a dataset with shape (H, W, 16)).
1. Physical Realizability Test
The prtest module offers several options to test the physical realizability of 4×4 Mueller matrices. These functions accept a 4×4 matrix representing a Mueller matrix and return a boolean result indicating whether the test is passed.
Available Test Methods:
charpoly: Characteristic Polynomial Testcholetsky: Cholesky Decomposition Test
Additionally, the function build_eigen_matrix computes the coherency matrix required by the tests.
Performance benchmarks and detailed implementations can be found in the original repository here.
2. Decomposition
The decomposition module provides a method for decomposing a Mueller matrix image into its optical parameters using the Lu-Chipman decomposition.
Decomposition Parameters:
MMD_D: DiattenuationMMD_Delta: DepolarizationMMD_LR: Linear RetardanceMMD_CR: Circular RetardanceMMD_psi: Orientation
The function lu_chipman accepts:
H_image: Height (number of rows) of the MM image.W_image: Width (number of columns) of the MM image.FinalM: A flattened MM image with shape(H_image, W_image, 16). Internally, this is reshaped into(H_image, W_image, 4, 4).
Reference:
Lu, S. Y., & Chipman, R. A. (1996). Interpretation of Mueller matrices based on polar decomposition. JOSA A, 13(5), 1106-1113.
How to Install
Install the package from PyPI:
pip install pymueller
import pymueller
Example Usage
A. Physical Realizability Tests (Single 4×4 Matrix)
import numpy as np
from pymueller.prtest import build_eigen_matrix, choletsky, charpoly
# Define a sample 4×4 Mueller matrix (for example, with a small perturbation)
M = np.array([
[1.0, 0.1, 0.2, 0.3],
[0.1, 1.0, 0.4, 0.5],
[0.2, 0.4, 1.0, 0.6],
[0.3, 0.5, 0.6, 1.0]
])
# Compute the coherency matrix (if needed)
H = build_eigen_matrix(M)
# Test physical realizability using two methods
if choletsky(M):
print("Matrix passed the Cholesky (choletsky) test.")
if charpoly(M):
print("Matrix passed the characteristic polynomial (charpoly) test.")
B. Decomposition on a Mueller Matrix Image
If you have an MM image (e.g., from a polarimetric imaging system) with shape (H, W, 16), you can decompose it into optical parameters. For example, here we generate a synthetic dataset where each 4×4 Mueller matrix is the identity plus a small random perturbation (to avoid divisions by zero):
import numpy as np
from pymueller.decomposition import lu_chipman
# Define image dimensions
H, W = 500, 500
# Create a synthetic MM image where each pixel is an identity 4×4 plus a small random noise.
identity = np.eye(4)
noise = np.random.uniform(low=-0.1, high=0.1, size=(H, W, 4, 4))
mm_matrices = identity + noise
# Reshape to (H, W, 16) as expected by lu_chipman
FinalM = mm_matrices.reshape(H, W, 16)
# Perform Lu-Chipman decomposition
MMD_D, MMD_Delta, MMD_LR, MMD_CR, MMD_psi = lu_chipman(H, W, FinalM)
print("Diattenuation (MMD_D):", MMD_D)
print("Depolarization (MMD_Delta):", MMD_Delta)
print("Linear Retardance (MMD_LR):", MMD_LR)
print("Circular Retardance (MMD_CR):", MMD_CR)
print("Orientation (MMD_psi):", MMD_psi)
Running the Tests
Running the Tests
The repository includes tests that:
- Generate synthetic MM image datasets.
- Loop through selected pixels to verify the physical realizability tests.
- Validate the decomposition outputs for a full MM image. To run all tests, simply execute:
python -m unittest discover -s tests
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 pymueller-0.1.3.tar.gz.
File metadata
- Download URL: pymueller-0.1.3.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc317c59b688fd966959e73c9ec9b737e7c38ec52bc614898e5ac2748ff77ad5
|
|
| MD5 |
23f9ad1a914f1750f9c071533e36a521
|
|
| BLAKE2b-256 |
ca98409696193c67785c5ccfd4c256351d19a8bec676c96a7f3e6b993605d643
|
File details
Details for the file pymueller-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pymueller-0.1.3-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3b65fb8986403190fb05d91ae26da0f04ddca072ba2e74d7f6cc71cbd055d22
|
|
| MD5 |
a4e743c4239207ccec548e66011e29d6
|
|
| BLAKE2b-256 |
cf4dc6fd4fdf4880458c5b0e6590b696012050abe79c52f3e1401aba1701edef
|