//calculate the phase of a row of a fringe pattern using the Cost Ridge Extraction Algorithm
int ridge_cost(float *wrapped_phase, double* Wavelet_Result_R, double* Wavelet_Result_C, double *Wavelet_magnitude, int image_width, int no_of_scales, NODE *nodes)
{
	int scale_matrix_size_int = image_width * no_of_scales;
	int i, j, current_node, previous_node;;
	double *diffrentiated_input = (double*) calloc(no_of_scales, sizeof(double));
	double *sub_cost = (double*) calloc(no_of_scales, sizeof(double));
	double Min = 999999999999999999.9;
	int MinPos_node, MinPos_scale, previous_link;

	for (i=0; i<scale_matrix_size_int; ++i)
	{
		Wavelet_magnitude[i] = sqrt(Wavelet_Result_R[i] * Wavelet_Result_R[i] + Wavelet_Result_C[i] * Wavelet_Result_C[i]);
	}

	//find the local minima and cost for all the row
	for (i=0; i<image_width; ++i)
	{
		local_maxima(Wavelet_magnitude + i, image_width, no_of_scales, nodes, i, diffrentiated_input);
		//find the cost function for all the nodes
		if (i > 0)
		{
			for (current_node = 0; current_node < nodes[i].no_of_local_maxima; ++current_node)
			{
				for (previous_node = 0; previous_node < nodes[i-1].no_of_local_maxima; ++previous_node)
				{
					sub_cost[previous_node] = nodes[i-1].cost[previous_node] +
						pow( (double) ((nodes[i].indices_local_maxima_scale[current_node] / image_width) - 
						(nodes[i-1].indices_local_maxima_scale[previous_node] / image_width)), 2.0) -
						pow((double)(nodes[i].local_maxima[current_node]), 2.0);
						
					//find the minimum of the subcost vector and assign it to the cost of the node
					if (sub_cost[previous_node] < Min)
					{
						Min = sub_cost[previous_node];
						MinPos_node = previous_node;

					}
				}
				nodes[i].cost[current_node] = Min;
				nodes[i].previous_link_node[current_node] = MinPos_node;
				Min = 999999999999999999.9;
			}
		}
		else
		{
			for (current_node=0; current_node < nodes[i].no_of_local_maxima; ++current_node)
			{
				nodes[i].cost[current_node] = 0;
				nodes[i].previous_link_node[current_node] = 0;
			}
		}//if
	} //for i
	
//find the minimum path through all the nodes (backward)
	int *optimal_path_indexes = (int *) calloc(image_width, sizeof(double));
	//find the minimum cost for the last node
	Min = 999999999999999999.9;
	for (j=0; j<nodes[image_width-1].no_of_local_maxima; ++j)
	{
		if (nodes[image_width-1].cost[j] < Min)
		{
			Min = nodes[image_width-1].cost[j];
			MinPos_scale = nodes[image_width-1].indices_local_maxima_scale[j];
			MinPos_node = j;
		}
	}
	optimal_path_indexes[image_width-1] = MinPos_scale;
	MinPos_node = nodes[image_width-1].previous_link_node[MinPos_node];

	//find the path for the rest of the nodes (right to left)
	for(i=image_width - 2; i > -1 ; --i)
	{
		optimal_path_indexes[i] = nodes[i].indices_local_maxima_scale[MinPos_node];
		MinPos_node = nodes[i].previous_link_node[MinPos_node];
	}

	//find the wrapped phase map for the row
	for (i=0; i<image_width; ++i)
	{
		wrapped_phase[i] = atan2(Wavelet_Result_C[ optimal_path_indexes[i] + i], Wavelet_Result_R[ optimal_path_indexes[i] + i]);
	}

	free(diffrentiated_input);
	free(optimal_path_indexes);
	free(sub_cost);
	return 0;
}
示例#2
0
文件: subseq.hpp 项目: dblalock/dig
static vector<length_t> local_maxima(const Container<data_t>& data,
		length_t minSpacing=1)
{
	return local_maxima(data.data(), data.size(), minSpacing);
}