A python package to reveal regularites from complex image data using correlations
Project description
Adjacent Correlation Analysis: Revealing Regularities in Image Data
Adjacent Correlation Analysis (ACA) is a Python package designed to uncover hidden regularities and relationships within image datasets by analyzing localized correlations. It provides tools for both Adjacent Correlation Analysis (visualizing correlations in phase space) and Adjacent Correlation Map (spatial mapping of correlation properties).
Documentation Available at: ReadTheDocs.
—
Features & Design
ACA helps you analyze relationships between two images (Numpy arrays of the same size) by comparing them through correlations. The core idea is to reveal adjacency-induced correlations that might be obscured when looking at global statistics.
The adjacent correlation analysis process involves calculating and visualizing the adjacency-induced correlation within the phase space defined by the two images. The adjacent correlation map then provides a spatially-resolved representation of these correlations.
These methods are specifically designed to represent data using correlations, facilitating powerful visualization and interactive data exploration.
—
Adjacent Correlation Analysis
The Adjacent Correlation Analysis method derives correlation vectors that can be plotted on top of the Probability Density Function (PDF) of the two image datasets. These vectors indicate the local correlation strength and direction within the phase space.
Application to MHD Turbulence Simulation Data: This example shows correlation vector fields overlaid on a density map (density PDF). The correlation degree represents the normalized length of the vector, and both the length and orientation are clearly visible in the adjacent correlation plot.
Application to the Lorentz System: Here, vectors derived using adjacent correlation analysis provide a projected view of the vector field in the phase space on the x-y plane, illustrating the system’s dynamic regularities.
—
Adjacent Correlation Map
The Adjacent Correlation Map provides spatially-resolved maps of the correlations between two images. It generates a correlation angle map, a correlation degree map, and a correlation coefficient map.
Application to Temperature and Precipitation Data: This output demonstrates the correlation angle map, correlation degree map, and correlation coefficient map (available as program output). The correlation angle map indicates the direction of the correlation in phase space, while the correlation degree map shows the strength of the correlation. Different colors highlight distinct correlation patterns between temperature (T) and log(precipitation).
—
References
If you utilize this software in your research, we kindly request you cite the following papers:
Adjacent Correlation Analysis:
Revealing hidden correlations from complex spatial distributions: Adjacent Correlation Analysis, Li (2025)
Adjacent Correlation Map:
Mapping correlations and coherence: adjacency-based approach to data visualization and regularity discovery, Li (2025)
—
Installation & Usage
Requirements:
Python 3.0 or higher
NumPy
SciPy
Matplotlib
Installation can be done using pip:
pip install -i https://test.pypi.org/simple/ adjacent-correlation-analysis==0.1.0
Alternatively, you can clone the repository and install it in editable mode:
git clone https://github.com/gxli/Adjacent-Correlation-Analysis
cd Adjacent-Correlation-Analysis
pip install -e .
How to Use
To perform the adjacent correlation analysis and generate a plot of the correlation vectors overlaid on the density map:
import adjacency_correlation_analysis as aca
import matplotlib.pyplot as plt
# xdata and ydata are your two image arrays
aca.adjacent_correlation_plot(xdata, ydata)
plt.show()
Available parameters for adjacent_correlation_plot:
bins: Number or sequence of bins used for density estimation. If None, an optimal bin size is automatically determined. Defaults to None.
ax: Matplotlib axes object to plot on. Defaults to plt.gca().
scale, cmap, etc.: Plotting parameters for customization.
**kwargs: Additional arguments passed to matplotlib.pyplot.imshow and matplotlib.pyplot.quiver.
cmap: Colormap to be used for the density map. Defaults to ‘viridis’.
facecolor: Face color of the quiver arrows. Defaults to ‘w’.
scale: Scaling factor for the quiver arrows. Defaults to 20.
lognorm: Whether to use logarithmic normalization for the density map. Defaults to False.
To compute the adjacent correlation vectors directly:
import numpy as np
import adjacency_correlation_analysis as aca
# xdata and ydata are your two image arrays
H, xedges, yedges = np.histogram2d(xdata, ydata)
ex, ey = aca.compute_correlation_vector(xdata, ydata, xedges, yedges)
Inputs:
xdata and ydata: The two input images (Numpy arrays) to be compared.
xedges and yedges: The bin edges used to compute the histogram for density estimation.
Outputs (tuple):
p: Degree of correlation.
nx: Normalized x-component of the correlation vector.
ny: Normalized y-component of the correlation vector.
i: Total intensity of the correlation vector, $i = sqrt{Ex^2 + Ey^2}$, where $Ex = frac{d p_1}{d x}$ and $Ey = frac{d p_2}{d x}$.
To visualize the computed vectors:
import matplotlib.pyplot as plt
import numpy as np
# Assuming ex, ey, xedges, yedges are already computed
xx = np.linspace(xedges[0], xedges[-1], len(xedges)-1)
yy = np.linspace(yedges[0], yedges[-1], len(yedges)-1)
x_grid, y_grid = np.meshgrid(xx, yy)
# Plotting the result
plt.quiver(x_grid, y_grid, ex.T, ey.T, facecolor='w', angles='xy', scale=30, headaxislength=0)
plt.show()
To compute the adjacent correlation map:
import adjacency_correlation_analysis as aca
# xdata and ydata are your two image arrays
p, angle, corr_coef, i = aca.compute_correlation_map(xdata, ydata)
Inputs:
xdata and ydata: The two input images (Numpy arrays) to be compared.
Outputs (tuple):
p: The correlation degree map, which is the normalized length of the correlation vector, $p = frac{l_{max}}{(l_{min}^2 + l_{max}^2)^{1/2}}$.
angle: The correlation angle map, representing the direction of the correlation in phase space, $angle = arctan2(Ey, Ex)$.
corr_coef: The correlation coefficient map, equivalent to the Pearson correlation coefficient.
i: The intensity map, representing the total gradient in the phase space, $i = sqrt{Ex^2 + Ey^2}$, where $Ex = frac{d p_1}{d x}$ and $Ey = frac{d p_2}{d x}$.
To visualize the map results:
import matplotlib.pyplot as plt
# Assuming p and angle are already computed
plt.imshow(p)
plt.imshow(angle)
plt.show()
—
Foundation of Adjacent Correlation Analysis
Adjacency-induced Correlations:
The methodology is rooted in the observation that image values measured in adjacent locations often exhibit stronger, more discernible correlations compared to values measured across an entire region. Consider the example of temperature and precipitation data across North America: when plotted globally, they may appear weakly correlated. However, by selecting localized regions (R1, R2, R3), distinct local correlations emerge—ranging from negative to positive to weak—that are otherwise obscured by the overall global average.
Adjacency-induced correlations: Values measured in small boxes (R1, R2, and R3) demonstrate stronger correlations than those measured over the entire region.
The adjacent correlation analysis is designed to reveal these localized correlations within the phase space, while the adjacent correlation map provides a spatial representation of these correlations in the measurement domain.
Given two images, $p_1(x, y)$ and $p_2(x, y)$, the adjacency correlation map comprises:
- A correlation angle map:
- \begin{equation*} \theta(x,y) = \arctan\left(\frac{ d p_2}{d p_1}\right) \end{equation*}
- A correlation degree map:
- \begin{equation*} p(x,y) = \frac{l_{max}}{(l_{min}^2 + l_{max}^2)^{1/2}} \end{equation*}
where $l_{min}$ and $l_{max}$ are the minimum and maximum lengths of the correlation ellipse.
- A correlation coefficient map:
- \begin{equation*} r(x,y) = \frac{\sigma(p_1 p_2)}{ \sigma(p_1) \sigma(p_2)} \end{equation*}
which is equivalent to the Pearson correlation coefficient.
The adjacent correlation plot then provides a visual representation of these correlations within the phase space.
—
Superimposing Correlations Using Stokes Parameters
To effectively superimpose the adjacent correlation vectors, we leverage Stokes parameters, commonly used to describe the polarization state of light. Here, they are adapted to represent the correlation vectors.
In the $p_1-p_2$ phase space, the correlation vector is defined as:
The pseudo-Stokes parameters are then defined as:
These Stokes parameters are used to combine and represent multiple correlation vectors. The correlation angle and degree can subsequently be computed from the Stokes parameters using:
From these, $E_x$ and $E_y$ can be re-derived.
—
Manifold Interpretation
What do the lines observed in the adjacent correlation plot signify?
For systems governed by partial differential equations (PDEs), rapid processes can constrain the system to a low-dimensional manifold within the phase space. On this manifold, local variations can be described by a vector field. The presence of slowly evolving variables ($C$) might play a role in separating different trajectories, which in turn correspond to distinct spatially coherent regions.
Consider the correlation between income and apartment size. When measured in localized regions, higher income often correlates with larger apartments, and vice versa. However, across an entire country, this correlation might appear weak. This is because apartment size is influenced not only by income but also by other hidden, slow-changing parameters such as GDP per capita, city size, etc. When these unmeasured parameters vary slowly across space, they can induce the observed local correlations.
Thus, the correlation vectors observed in the adjacent correlation plot tend to follow lines of constant $C$, where $C$ represents a hidden, slow-varying parameter.
—
Interactive Data Exploration
Adjacent Correlation Analysis is designed to be highly compatible with interactive visualization tools. We recommend using software like Glue to explore your data interact capabilities.
Interactive Data Exploration: ACA facilitates interactive exploration of complex datasets, revealing insights that might be missed with static visualizations.
—
Contribute
We welcome contributions to the Adjacent Correlation Analysis project!
Issue Tracker: github.com/Adjacent-Correlation-Analysis/issues
Source Code: github.com/Adjacent-Correlation-Analysis
—
Support
If you encounter any issues or have questions, please reach out. We have a mailing list available at: https://groups.google.com/g/adjacentcorrelationanalysis
—
License
The project is licensed under the GPLv3.
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 adjacent_correlation_analysis-0.1.1.tar.gz.
File metadata
- Download URL: adjacent_correlation_analysis-0.1.1.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4854e46ec47bcaa8cd3c2efcd328dfe61388f52b02166565171a8fd374405fad
|
|
| MD5 |
88f247fac5cf6a9adaa9224e3d7e6a59
|
|
| BLAKE2b-256 |
2789656c1648f2262fe1c03fa22f3de388b3e16b3f86d31067f1bfe9214b10aa
|
File details
Details for the file adjacent_correlation_analysis-0.1.1-py3-none-any.whl.
File metadata
- Download URL: adjacent_correlation_analysis-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a712760733b059c13696c6d898bc27c92206318c790507c610549b899c0ad1
|
|
| MD5 |
4c6b1b5ddc52ab0db783b11858964e2a
|
|
| BLAKE2b-256 |
37c7206328897d716651edbd47ce58099d587a0848dc85a14fc2967bf7227855
|