#include "header.h" /* Written by Waqas Akram, Justin Romberg, & Charles Gamiz, May 1997 */ /* global variables - image and the size of the image */ int **IMAGE; double **GRADIENT; int *sizeI; int **START; int *sizeST; double intThresh; double intStd; int COUNT; /* main regiongrow function */ /* arguments: */ /* 1: image matlab filename */ /* 2: smoothed gradient of image filename */ /* 3: starting point vector filename */ /* 4: intensity threshold value */ /* 5: standard deviation of intensity values */ /* 6: mask level */ void main(int argc, char * argv[]) { /* create global structures */ FILE * imagefile; FILE * gradfile; FILE * startfile; int ** EDGE; int ** CELL; struct pixel * point; struct region * R; struct region * tmpR; struct region * R_HEAD; int j; int c; int masklevel; if (argc != 7) { printf("ERROR: incorrect number of arguments.\n"); return; } masklevel = atoi(argv[6]); /* open file containing image */ imagefile = fopen(argv[1], "r"); /* read in the size of the image */ /* (the number of rows and columns) */ sizeI = (int*)calloc(2, sizeof(int)); fread(sizeI, sizeof(int), 2, imagefile); /* read the image out of the file */ IMAGE = ReadImageFile(imagefile, sizeI); /* open file containing the gradient and read into array*/ gradfile = fopen(argv[2], "r"); GRADIENT = ReadGradientFile(gradfile); /* read in the threshold and std values */ intThresh = atof(argv[4]); intStd = atof(argv[5]); /* open file containg starting vector */ startfile = fopen(argv[3], "r"); /* read in size of the starting vector */ sizeST = (int*)calloc(2, sizeof(int)); fread(sizeST, sizeof(int), 2, startfile); printf("%d, %d\n", sizeST[0], sizeST[1]); /* read the starting vector itself */ START = ReadStartFile(startfile, sizeST); /*for (j=0; j < sizeST[0]; j++) { printf("%d %d\n", START[j][0], START[j][1]); }*/ /* grow the regions given by the starting points */ COUNT = 0; R_HEAD = NULL; R = NULL; for (j=0; j < sizeST[0]; j++) { /* allocate reference point */ point = create_pixel(START[j][0], START[j][1]); /* call main region growing function */ tmpR = grow_region(point); if (tmpR == NULL) { printf("Error in grow_region %d.\n", j); } if (R_HEAD == NULL) { R_HEAD = tmpR; R = tmpR; } else if (R->next == NULL) { R->next = tmpR; } else { R = R->next; R->next = tmpR; } } /*printf("AddPixel count = %d\n", COUNT);*/ /* VIS = create_visit(R->visit); */ EDGE = NULL; CELL = NULL; R = R_HEAD; c = 0; while (R != NULL) { c++; EDGE = create_mask(EDGE, R->edge_list, masklevel); CELL = create_mask(CELL, R->pixel_list, masklevel); R = R->next; } /*printf("count = %d", c);*/ /*DumpRegion(R);*/ WriteImageFile("edge.ajw", EDGE, sizeI); WriteImageFile("cell.ajw", CELL, sizeI); }