Metadata-Version: 2.4
Name: robust_2d_unwrap
Version: 0.1.0
Summary: Robust 2D Unwrapping Algorithm by Zixin Zhao, ported to Python.
Author: Andrew Humphreys, Zixin Zhao
License: Copyright (c) 2018, Zixin Zhao
        Copyright (c) 2026, Andrew Humphreys
        Copyright (c) 2026, SRICO, Inc.
        All rights reserved.
         
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
         
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
         
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution
        * Neither the name of Xi'an Jiaotong University nor the names of its
          contributors may be used to endorse or promote products derived from this
          software without specific prior written permission.
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# robust\_2d\_unwrap

The following is an implementation of the algorithm proposed in "Robust 2D phase unwrapping algorithm based on the transport of intensity equation" ([DOI:10.1088/1361-6501/aaec5c](https://doi.org/10.1088/1361-6501/aaec5c)) by Zixin Zhao, Hangying Zhang, Zhaoxian Xiao, Hubing Du, Yiying Zhuang, Chen Fan and Hong Zhao.

In particular, the code is directly ported from the [MatLab implementation](https://www.mathworks.com/matlabcentral/fileexchange/68493-robust-2d-phase-unwrapping-algorithm) to be python compatible. 


## Installation with pip
```bash
pip install robust_2d_unwrap
```

## Basic Usage

```python
import numpy as np
from robust_2d_unwrap import unwrap
import matplotlib.pyplot as plt

# Generate a surface, with wrapped phase for every point
h,w = 640, 480
y0, x0 = (h - 1) / 2, (w - 1) / 2
y = np.arange(h)
x = np.arange(w)
Y, X = np.meshgrid(y,x, indexing='ij')
hmap = 4 * np.exp( -( ((Y - y0)**2) / (2 * 100**2) + ((X - x0)**2) / (2 * 100**2) ))
abs_phase = hmap * 2 * np.pi
wrapped_phase = (abs_phase + np.pi) % (2 * np.pi) - np.pi

# add some noise
wrapped_phase += np.random.randn(h,w) # mu=0, std=1 rad

# visualise wrapped phase
plt.imshow(wrapped_phase) # 2d headmap
plt.title('Wrapped Phase w/ Noise')
plt.show()

# wrap phase
unwrapped_phase, _ = unwrap(wrapped_phase)

# visualize result
plt.imshow(unwrapped_phase)
plt.title('Unwrapped Phase')
plt.show()

# Noise will persist, but it will not break the unwrapping
# algorithm.
```
