In this tutorial, you will learn how to use the phase unwrapping module to unwrap two-dimensional phase maps. The implementation is based on [157].
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
static const char* keys =
{
"{@inputPath | | Path of the wrapped phase map saved in a yaml file }"
"{@outputUnwrappedName | | Path of the unwrapped phase map to be saved in a yaml file and as an 8 bit png}"
};
static void help()
{
cout << "\nThis example shows how to use the \"Phase unwrapping module\" to unwrap a phase map"
" saved in a yaml file (see extra_data\\phase_unwrapping\\data\\wrappedpeaks.yml)."
" The mat name in the file should be \"phaseValue\". The result is saved in a yaml file"
" too. Two images (wrapped.png and output_name.png) are also created"
" for visualization purpose."
"\nTo call: ./example_phase_unwrapping_unwrap <input_path> <output_unwrapped_name> \n"
<< endl;
}
int main(
int argc,
char **argv)
{
if( inputPath.empty() || outputUnwrappedName.empty() )
{
help();
return -1;
}
FileStorage fsOutput(outputUnwrappedName +
".yml", FileStorage::WRITE);
fsInput["phaseValues"] >> wPhaseMap;
phaseUnwrapping->unwrapPhaseMap(wPhaseMap, uPhaseMap);
fsOutput << "phaseValues" << uPhaseMap;
phaseUnwrapping->getInverseReliabilityMap(reliabilities);
Mat uPhaseMap8, wPhaseMap8, reliabilities8;
uPhaseMap.convertTo(uPhaseMap8,
CV_8U, 1, 128);
imshow("reliabilities", reliabilities);
imshow("wrapped phase map", wPhaseMap8);
imshow("unwrapped phase map", uPhaseMap8);
imwrite(outputUnwrappedName + ".png", uPhaseMap8);
imwrite("reliabilities.png", reliabilities8);
bool loop = true;
while( loop )
{
char key = (char)waitKey(0);
if( key == 27 )
{
loop = false;
}
}
return 0;
}
Designed for command line parsing.
Definition utility.hpp:890
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...
Definition persistence.hpp:261
n-dimensional dense array class
Definition mat.hpp:950
int cols
Definition mat.hpp:2424
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition mat.hpp:2424
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Converts an array to another data type with optional scaling.
void release()
Decrements the reference counter and deallocates the matrix if needed.
std::string String
Definition cvstd.hpp:151
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
#define CV_8U
Definition interface.h:76
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Parameters of phaseUnwrapping constructor.
Definition histogramphaseunwrapping.hpp:79
int width
Definition histogramphaseunwrapping.hpp:81
int height
Definition histogramphaseunwrapping.hpp:82
To use this example, wrapped phase map values should be stored in a yml file as CV_32FC1 Mat, under the name "phaseValues". Path to the data and a name to save the unwrapped phase map must be set in the command line. The results are saved with floating point precision in a yml file and as an 8-bit image for visualization purpose.
The wrapped phase map is unwrapped and the result is saved in a yml file. We can also get the reliabilities map for visualization purpose. The unwrapped phase map and the reliabilities map are converted to 8-bit images in order to be saved as png files.
phaseUnwrapping->unwrapPhaseMap(wPhaseMap, uPhaseMap);
fsOutput << "phaseValues" << uPhaseMap;
phaseUnwrapping->getInverseReliabilityMap(reliabilities);
Mat uPhaseMap8, wPhaseMap8, reliabilities8;
uPhaseMap.convertTo(uPhaseMap8,
CV_8U, 1, 128);
imshow("reliabilities", reliabilities);
imshow("wrapped phase map", wPhaseMap8);
imshow("unwrapped phase map", uPhaseMap8);
imwrite(outputUnwrappedName + ".png", uPhaseMap8);
imwrite("reliabilities.png", reliabilities8);