File Exchange

image thumbnail

2D and 3D Phase Unwrapping using SRNCP

version 3.0.2 (7.19 KB) by Michael Mullen
2D & 3D phase unwrapping plugins for Matlab


Updated 03 Jun 2020

GitHub view license on GitHub

These files provide a means to implement the above algorithm without any special packages/toolboxes and needs any Matlab compatible C++ compiler (used Visual Studio 2019 version for this).

To compile:
mex phaseUnwrap.cpp

Input must be a real, double matrix from Matlab.

Cite As

Michael Mullen (2020). 2D and 3D Phase Unwrapping using SRNCP (, GitHub. Retrieved .

Comments and Ratings (12)

It seems that using

mex -compatibleArrayDims phaseUnwrapC.c

fixes the issues with the seg fault on newer versions of Matlab. Haven't dug into why much yet, as there aren't any uses of int... only mwSize. Hope it works for everyone.

cheng yang

Thank you all for the feedback. Unfortunately, I (the contributor of this package) do not have access to Matlab 2018a. I will look into potential causes as soon as possible.

Also, I have not implemented this to work on a GPU. I apologize for any inconvenience this may cause.

Omri BarLev

I desperately need 2D phase unwrapping for large matrices.
However, as previously mentioned, I encountered the same problem as Thuc Phan.

Is there a GPU code for 2D phase unwrapping ?

ChiaJan Yv

I encountered the same problem as Thuc Phan.

Thuc Phan

Hi. I use Visual Studio Community 2015 and MATLAB R2018a to run MEX file version.

>> mex phaseUnwrapC.c
Building with 'Microsoft Visual C++ 2015 (C)'.
MEX completed successfully.

>> unwrappedImage = phaseUnwrapC(wrapped);
It popup a MathWorks Crash Reporter
MATLAB has encountered an internal problem and needs to close.

So I guess it cannot work with MATLAB 2018a. Hope someone can figure it out.



It's working on my side, and the mex indeed provides a significant speed up (25 sec vs. 140 sec on 334x334 images).
Matlab crashed the first time I ran phaseUnwrapC (segfault), but then worked... weird
>>Caught "std::exception" Exception message is:
>>Caught MathWorks::System::FatalException

I have MacOS with Matlab 2015a and XCode 8.
Mex compilation didn't work out of the box (everytime I update the OS or XCode, the whole thing breaks.)

I had to download the files here:
and change the xml files as instructed here (basically replace all "MacOSX10.10.sdk" by "MacOSX10.10.sdk")

I was sidetracked with other projects in the middle of testing the mex file, but I'm hoping to get around to this in the next few weeks. Also, thank you for the review; I'm glad it's working well for you!


Works very well, out-of-the-box, and doesn't require any Matlab toolbox (always annoying.)
Thanks for providing this!
It is reasonably fast already, but I would be interested in trying the MEX version that is mentioned in the description. Where can this one be found?



See release notes for this release on GitHub:


Organized/commented more thoroughly. No dramatic difference in performance.

Made compatible for 2D or 3D input phase images. Be patient with 3D.

Made C version more stable.

Found workaround to bug in previous version and updated with a C++ version to utilize som stl features.

Working excellently now, unwraps a 512x512 matrix in about 4 seconds with my system specs (compared to 45 seconds for version 2.4).

Found the bug a bit faster than anticipated. Anyway, tested to work with a 512x512 matrix now! A little slow at that size, but working to speed things up. At least it seems stable now.

Fixed bug in sorting algorithm, narrowing in on problems with large arrays.

Fixed a couple bugs in 2.1. Issue with large arrays persists.

Obtained another modest speedup. Seg fault happens for large arrays (somewhere between 300x300 and 400x400), working to fix this.

Version 2.0 includes the first version's Matlab only implementation, as well as a MEX file implementation which is about 4-5x faster.

File did not update with v1.02

Obtained a modest speed-up by eliminating some for-loops and using local functions.

Updated the description, not the files

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux