// Start Initialize Pixels // Initially every pixel is assumed to belong to a group of only itself // Initialize with random reliabilities private static void initialisePIXELs(float *wrapped_image, PIXELM *pixel, int image_width, int image_height) { Random random = new Random(); PIXELM *pixel_pointer = pixel; float * wrapped_image_pointer = wrapped_image; for (int i = 0; i < image_height; i++) { for (int j = 0; j < image_width; j++) { pixel_pointer->increment = 0; pixel_pointer->number_of_pixels_in_group = 1; pixel_pointer->value = *wrapped_image_pointer; pixel_pointer->reliability = random.Next(0, Int32.MaxValue); //pixel_pointer->input_mask = *input_mask_pointer; //pixel_pointer->extended_mask = *extended_mask_pointer; pixel_pointer->head = pixel_pointer; pixel_pointer->last = pixel_pointer; pixel_pointer->next = null; pixel_pointer->new_group = 0; pixel_pointer->group_number = -1; pixel_pointer++; wrapped_image_pointer++; //extended_mask_pointer++; } } }
// calculate the reliability of the vertical edges of the image // it is calculated by adding the reliability of pixel and the relibility of // its lower neighbour in the image. private static void verticalEDGEs(PIXELM *pixel, EDGE *edge, int image_width, int image_height, params_t *myparams) { int no_of_edges = myparams->no_of_edges; PIXELM *pixel_pointer = pixel; EDGE * edge_pointer = edge + no_of_edges; for (int i = 0; i < image_height - 1; i++) { for (int j = 0; j < image_width; j++) { //if (pixel_pointer->input_mask == NOMASK && // (pixel_pointer + image_width)->input_mask == NOMASK) //{ edge_pointer->pointer_1 = pixel_pointer; edge_pointer->pointer_2 = (pixel_pointer + image_width); edge_pointer->reliab = pixel_pointer->reliability + (pixel_pointer + image_width)->reliability; edge_pointer->increment = find_wrap( pixel_pointer->value, (pixel_pointer + image_width)->value); edge_pointer++; no_of_edges++; //} pixel_pointer++; } // j loop } // i loop myparams->no_of_edges = no_of_edges; }
// calculate the reliability of the horizontal edges of the image // it is calculated by adding the reliability of pixel and the relibility of // its right-hand neighbour // edge is calculated between a pixel and its next neighbour private static void horizontalEDGEs(PIXELM *pixel, EDGE *edge, int image_width, int image_height, params_t *myparams) { EDGE * edge_pointer = edge; PIXELM *pixel_pointer = pixel; int no_of_edges = myparams->no_of_edges; for (int i = 0; i < image_height; i++) { for (int j = 0; j < image_width - 1; j++) { //if (pixel_pointer->input_mask == NOMASK && // (pixel_pointer + 1)->input_mask == NOMASK) //{ edge_pointer->pointer_1 = pixel_pointer; edge_pointer->pointer_2 = (pixel_pointer + 1); edge_pointer->reliab = pixel_pointer->reliability + (pixel_pointer + 1)->reliability; edge_pointer->increment = find_wrap(pixel_pointer->value, (pixel_pointer + 1)->value); edge_pointer++; no_of_edges++; //} pixel_pointer++; } //pixel_pointer++; } myparams->no_of_edges = no_of_edges; }
private static void calculate_reliability(float *wrappedImage, PIXELM *pixel, int image_width, int image_height, params_t *myparams) { int image_width_plus_one = image_width + 1; int image_width_minus_one = image_width - 1; PIXELM *pixel_pointer = pixel + image_width_plus_one; float * WIP = wrappedImage + image_width_plus_one; // WIP is the wrapped image pointer float H, V, D1, D2; int i, j; for (i = 1; i < image_height - 1; ++i) { for (j = 1; j < image_width - 1; ++j) { H = wrap(*(WIP - 1) - *WIP) - wrap(*WIP - *(WIP + 1)); V = wrap(*(WIP - image_width) - *WIP) - wrap(*WIP - *(WIP + image_width)); D1 = wrap(*(WIP - image_width_plus_one) - *WIP) - wrap(*WIP - *(WIP + image_width_plus_one)); D2 = wrap(*(WIP - image_width_minus_one) - *WIP) - wrap(*WIP - *(WIP + image_width_minus_one)); pixel_pointer->reliability = H * H + V * V + D1 * D1 + D2 * D2; pixel_pointer++; WIP++; } pixel_pointer += 2; WIP += 2; } }
// the input to this unwrapper is an array that contains the wrapped // phase map. copy the image on the buffer passed to this unwrapper to // over-write the unwrapped phase map on the buffer of the wrapped // phase map. private static void returnImage(PIXELM *pixel, float *unwrapped_image, int image_width, int image_height) { int i; int image_size = image_width * image_height; float * unwrapped_image_pointer = unwrapped_image; PIXELM *pixel_pointer = pixel; for (i = 0; i < image_size; i++) { *unwrapped_image_pointer = pixel_pointer->value; pixel_pointer++; unwrapped_image_pointer++; } }
// unwrap the image private static void unwrapImage(PIXELM *pixel, int image_width, int image_height) { int i; int image_size = image_width * image_height; PIXELM *pixel_pointer = pixel; for (i = 0; i < image_size; i++) { if (pixel_pointer->increment != 0) { pixel_pointer->value += TWOPI * (float)(pixel_pointer->increment); } pixel_pointer++; } }