/**************************************************************************
INPUT: A 2D/3D wrapped phase image
Example: unwrapped = phaseUnwrap(wrapped);
Matlab R2016a
uses 3D-SRNCP version of 2D-SRNCP
/*************************************************************************/
#include "mex.h"
#include <math.h>
#include "matrix.h"
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <stdexcept>
#include <iostream>
//======================================================================
// BASIC FUNCTIONS HERE
//======================================================================
const double M_PI = 4.0 * atan(1.0);
using namespace std;
//Function to unwrap two adjacent pixels
double pairwiseUnwrap(double phase1, double phase2){
while(fabs(phase1-phase2) > M_PI){
if(phase1 > phase2 + M_PI){
phase1 = phase1 - 2*M_PI;
}
else if (phase1 < phase2 - M_PI){
phase1 = phase1 + 2*M_PI;
}
else{
break;
}
}
double result = phase1 - phase2;
return result;
};
//Information on edges
struct edgeInfo {
char edgeType = 'n'; //horizontal, vertical, or page edge ('r', 'c', or 'p', respectively)
double R; //reliability
long int row; //indices of pixel
long int column;
long int page;
// for sorting, intentionally overloaded < operator with > operator to get decreasing sort.
bool operator < (const edgeInfo& val) const
{
return (R > val.R);
}
};
//Keeps track of which phase group a given pixel belongs to.
// Can I replace these with multimaps?
struct pixelGroup {
long int group;
long int nextIndex;
long int firstIndex;
long int lastIndex;
};
//makes code a little clearer when grabbing indices of adjacent voxels.
inline long int get3Dindex(const long int row, const long int col, const long int page,
const long int numCols, const long int numRows) {
return col + (row)*numCols + page*numCols*numRows;
}
//calculate reliability of each edge.
void calcEdges(vector <pixelGroup>& groupArray, vector<edgeInfo>& edges, const long int numRows,
const long int numCols, const long int numPages, const vector<double>& Reliability){
long int colIndex, rowIndex, pageIndex,count = 0;
double rowEdge, columnEdge, pageEdge;
for (long int index = 0; index < numRows * numCols * numPages; index++) {
colIndex = index % numCols;
rowIndex = ((index % (numRows * numCols)) - colIndex) / numCols;
pageIndex = (index - rowIndex * numCols - colIndex) / (numRows * numCols);
if (rowIndex < numRows - 1) {
rowEdge = Reliability[get3Dindex(rowIndex, colIndex, pageIndex,numCols,numRows)]
+ Reliability[get3Dindex(rowIndex+1, colIndex, pageIndex, numCols, numRows)];
edges[count].edgeType = 'r';
edges[count].R = rowEdge;
edges[count].row = rowIndex;
edges[count].column = colIndex;
edges[count].page = pageIndex;
++count;
}
if (colIndex < numCols - 1) {
columnEdge = Reliability[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]
+ Reliability[get3Dindex(rowIndex, colIndex+1, pageIndex, numCols, numRows)];
edges[count].edgeType = 'c';
edges[count].R = columnEdge;
edges[count].row = rowIndex;
edges[count].column = colIndex;
edges[count].page = pageIndex;
++count;
}
if (pageIndex < numPages - 1) {
pageEdge = Reliability[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]
+ Reliability[get3Dindex(rowIndex, colIndex, pageIndex+1, numCols, numRows)];
edges[count].edgeType = 'p';
edges[count].R = columnEdge;
edges[count].row = rowIndex;
edges[count].column = colIndex;
edges[count].page = pageIndex;
++count;
}
groupArray[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)].group = get3Dindex(rowIndex, colIndex, pageIndex,numCols,numRows);
groupArray[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)].nextIndex = -1;
groupArray[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)].lastIndex = get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows);
groupArray[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)].firstIndex = get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows);
}
}
//Reliability calculation
//Calculates second differenc in phase across all non-border pixels
//Includes diagonal phase differences
void calcReliability(vector<double>& Reliability, const double* unwrappedImage, const int& numRows,
const int& numCols, const long int numPages) {
//horizontal, vertical, in-plane diagonals, page, through-page diagonals.
double H, V, D1, D2;
double P = 0, PD1 = 0, PD2 = 0, PD3 = 0, PD4 = 0;
//End result stored in D
double D;
int colIndex, rowIndex, pageIndex;
for (int index = 0; index < numRows * numCols * numPages; index++) {
//protect against out of range errors hopefully. Had some past issues in that regard.
try {
colIndex = index % numCols;
rowIndex = ((index % (numRows * numCols)) - colIndex) / numCols;
pageIndex = (index - rowIndex * numCols - colIndex) / (numRows * numCols);
if (rowIndex > 0 && rowIndex < numRows - 1 && colIndex > 0 && colIndex < numCols - 1) {
H = pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex-1, colIndex, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]) -
pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex+1, colIndex, pageIndex, numCols, numRows)]);
V = pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex-1, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]) -
pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex+1, pageIndex, numCols, numRows)]);
D1 = pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex-1, colIndex-1, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]) -
pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex+1, colIndex+1, pageIndex, numCols, numRows)]);
D2 = pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex-1, colIndex+1, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]) -
pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex+1, colIndex-1, pageIndex, numCols, numRows)]);
if (pageIndex > 0 && pageIndex < numPages - 1) {
P = pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex - 1, numCols, numRows)],
unwrappedImage[get3Dindex(rowIndex, colIndex, pageIndex, numCols, numRows)]) -
pairwiseUnwrap(unwrappedImage[get3Dindex(rowIndex, colIndex, page
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
由于干涉条纹中存在的噪声会引入伪相位,有时候因某个像素点的伪解包会导致一条线上的相位都解包异常,从而在面形图中产生一条异常直线。为了解决这一错误的传播和发生,研究人员开发了许多相位展开算法,并对其中一些算法进行了解释。此外,在利物浦约翰摩尔斯大学(LJMU)的通用工程研究所(GERI)开发了一种稳健的2D相位展开算法,称为2D-SRNCP相位展开器:该算法基于可靠性排序,遵循非连续路径,在处理破坏真实包裹相位图像的噪声方面表现出优异的性能。不要担心它如何工作的细节,只需将其视为一种非常先进和健壮的展开算法,并将其用作工具。 2D-SRNCP相位解包裹(Matlab和C代码):主程序(Main.m)是Matlab代码,解包程序(phaseUnwrap.cpp)是C代码(Matlab可直接调用)。 详细解释请见我的CSDN文章:https://blog.csdn.net/Loveoptics/article/details/123697805
资源推荐
资源详情
资源评论
收起资源包目录
2D-SRNCP phase unwrapper.zip (7个子文件)
2D-SRNCP phase unwrapper
phaseUnwrap.mexw64 846KB
phaseUnwrap.cpp 19KB
4步移相测试图
2.bmp 65KB
1.bmp 65KB
4.bmp 65KB
3.bmp 65KB
Main.m 783B
共 7 条
- 1
光学码农
- 粉丝: 6956
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页