Esempio n. 1
0
void intArray3D()
{
    int ***buf;
    int h, i, j;

    buf = allocate3D(3,10,10);
    
    for(h = 0; h < 3; h++)
    {
        for(i = 0; i < 10; i++)
        {
            for(j = 0; j < 10; j++)
            {
                if(i == j)
                    buf[h][i][j] = h;
                else
                    buf[h][i][j] = 0;

            }
        }
    }
    printArray(buf);
}
Esempio n. 2
0
int main(int argc, char **argv) {
//void main() {

	FILE     *output; //keypoint output (text)
	Image    *sourceImage, *sourceImage2;
	Image    *doubledImage;
	Image    *currentImage;
	Octave   *octavesList;
	Octave   *temp, *current;
	KeyPoint *peaks;
	KeyPoint *counter, *prevPoint;
	KeyPoint *keypoints, *keyCounter;
	int      candidates = 0;
	double   scale;
	double   ***mags, ***directions;
	int      octaveCount;
	int      tempHeight, tempWidth, tempDepth;
	int      totalKeypoints = 0;
	double   imageSigma;
	char     fileName[32] = {'\0'};
	FILE     *candidateOutput;
	FILE     *trashOutput;
	FILE     *filteredOutput;
/*
	if(argc < 2) {
		printf("Usage: sift dat_file\n");
		return 0;
	}
*/
	/* read input */
	//sourceImage = readPGMFile(argv[1]);
	sourceImage = readDATFile("./image.dat");
	if(sourceImage == NULL) {
		printf("file was not read\n");
		return 1;
	}
	scale = START_SCALE;

	/* print constants used */
	printf("Constants:\n");
	printf("START_SIGMA=%f\n", START_SIGMA);
	printf("OCTAVE_LIMIT=%d\n", OCTAVE_LIMIT);
	printf("IMAGES_PER_OCTAVE=%d\n", IMAGES_PER_OCTAVE);
	printf("SKIP_OCTAVES=%d\n", SKIP_OCTAVES);
	printf("MIN_SIZE=%d\n", MIN_SIZE);
	printf("MAX_ADJ_STEPS=%d\n", MAX_ADJ_STEPS);
	printf("EDGE_RATIO=%f\n", EDGE_RATIO);
	printf("CONTRAST_THRESH=%f\n", CONTRAST_THRESH);
	printf("CAP=%f\n", CAP);

	/* double image to save data */
	doubledImage = doubleImage(sourceImage);
	if(doubledImage == NULL) {
		return 1;
	}
	scale /= 2.0;
	printf("\nImage doubled\n");

	/* preprocessing smoothing*/
	printf("Preprocessing smoothing\n");
	doubledImage = gaussianConvolution2DFast(doubledImage, 1.0);
//	doubledImage = gaussianConvolution2DFast(sourceImage, 1.0);

	/* build octaves of scalespace */
	printf("Octave pyramid construction\n");
	currentImage = doubledImage;
	octavesList = NULL;
	octaveCount = 0;
	while(octaveCount < OCTAVE_LIMIT && currentImage->width >= MIN_SIZE && currentImage->height >= MIN_SIZE) {
		if(currentImage == NULL) {
			printf("  ***Current image null. Exiting.\n");
			return 1;
		}

		/* create octave pointer wrapper */
		printf("  Octave for pic %d %d (%d)\n", currentImage->width, currentImage->height, octaveCount);
		temp = (Octave *) malloc(sizeof(Octave));
		if(temp == NULL) {
			printf("  ***Out of memory. Exiting.\n");
			return 1;
		}
		/* build scale space L(x,y,sigma) */
		printf("    Gaussian Scale Space\n");
		if(octaveCount == 0)
			imageSigma = 1.0; //blur of the first image is 1.0
		else
			imageSigma = START_SIGMA;
		temp->gaussianSpace = buildScaleSpaceOctave(currentImage, scale, imageSigma);

		/* build diff space D(x,y,sigma) */
		printf("    Diff Gaussian Space\n");
		temp->diffGaussianSpace = buildDifferences(temp->gaussianSpace);

		/* store and go on */
		octavesList = link(octavesList, temp);
		currentImage = halveImage(getLastImage(temp->gaussianSpace));
		scale *= 2.0;
		++octaveCount;
		printf("    Image halved\n");
	}
	--octaveCount; /* one extra */

	/* generate keypoints from each octave of scalespace */
	printf("Keypoint generation\n");
	candidateOutput = fopen("output_candidates.txt", "w"); //helpful output file
	trashOutput = fopen("output_trash.txt", "w"); //helpful output file
	filteredOutput = fopen("output_filtered.txt", "w"); //helpful output file
	
	histOutput = fopen("output_histogram.txt", "w"); //outputs histograms
	histOutput2 = fopen("output_histogram2.txt", "w"); //turn on/off in scalespace.c
	
	keypoints = NULL;
	sourceImage2 = cloneImage(sourceImage);
	for(current = octavesList; current != NULL && octaveCount >= SKIP_OCTAVES; current = current->next, --octaveCount) {
		printf("  Octave %d\n", octaveCount);
		fprintf(histOutput, "Octave %d\n", octaveCount);
		fprintf(histOutput, "---------\n");
		fprintf(histOutput2, "Octave %d\n", octaveCount);
		fprintf(histOutput2, "---------\n");

		/* find keypoint candidates */
		printf("    Looking for peaks\n");
		peaks = getPeaks(current);
		/* temporary output */
		scale = current->diffGaussianSpace->imageScale;
		printPoints(candidateOutput, peaks, scale, octaveCount);
		markImageSPoint(peaks, sourceImage2, scale); //output candidates
		if(peaks != NULL)
			printf("      found %d candidates\n", peaks->count);
		else
			printf("      found 0 candidates\n");

		/* filter peaks for contrast and edge-iness and localize them */
		printf("    Filtering and localizing\n");
		trash = NULL;
		peaks = filterAndLocalizePeaks(current->diffGaussianSpace, current->gaussianSpace, peaks);

		/* temporary output */
		printPoints(filteredOutput, peaks, scale, octaveCount);
		printTrashed(trashOutput, trash, scale, octaveCount);
		if(peaks != NULL)
			printf("      have %d candidates remaining\n", peaks->count);
		else
			printf("      have 0 candidates remaining\n");

		/* precompute magnitudes and orientations */
		printf("    Generating magnitudes and orientations\n");
		tempHeight = current->gaussianSpace->imgHeight;
		tempWidth = current->gaussianSpace->imgWidth;
		tempDepth = current->gaussianSpace->imageCount - 2;
		current->gaussianSpace->magnitudes = allocate3D(tempHeight, tempWidth, tempDepth);
		current->gaussianSpace->directions = allocate3D(tempHeight, tempWidth, tempDepth);
		getMagnitudesAndOrientations(current->gaussianSpace);

		/* assign orientation(s) */
		printf("    Assigning orientation(s)\n");
		generateKeypoints(current->gaussianSpace, peaks);

		/* generate descriptors*/
		printf("    Calculating descriptors\n");
		createDescriptors(current->gaussianSpace, peaks);

		/* multiply by imgScale to get real values */
		for(counter = peaks; counter != NULL; counter = counter->next) {
			counter->finalX *= counter->imgScale;
			counter->finalY *= counter->imgScale;
			//also multiply x,y?
			counter->scale *= counter->imgScale;
		}

		/* merge lists */
		if(peaks != NULL) {
			if(keypoints != NULL) {
				keypoints->listRear->next = peaks;
				keypoints->listRear = peaks->listRear;
			}
			else
				keypoints = peaks;
		}

		/* deallocate memory */
		deallocate3D(current->gaussianSpace->magnitudes, tempHeight, tempWidth);
		deallocate3D(current->gaussianSpace->directions, tempHeight, tempWidth);

		/* deallocate trashed points */
		counter = trash;
		prevPoint = NULL;
		while(counter != NULL) {
			prevPoint = counter;
			counter = counter->next;
			free(prevPoint);
		}
	}

	fclose(histOutput);
	fclose(histOutput2);

	/* write footer to each file */
	printFooter(candidateOutput);
	fclose(candidateOutput);
	printFooter(trashOutput);
	fclose(trashOutput);
	printFooter(filteredOutput);
	fclose(filteredOutput);

	/* output keypoint descriptors */
	printf("Output\n");
	output = fopen("output.txt", "w");
	for(keyCounter = keypoints; keyCounter != NULL; keyCounter=keyCounter->next) {
		++totalKeypoints;
	}
	fprintf(output, "%d %d\n", totalKeypoints, 128);
	for(keyCounter = keypoints; keyCounter != NULL; keyCounter=keyCounter->next) {
		printKeyPoint(keyCounter, output);
	}
	fclose(output);

	/* output keypoints on image*/
	markImage(keypoints, sourceImage);
	writeDATFile(sourceImage, "./output/keypoints.dat");

	/* output initial candidates on image */
	writeDATFile(sourceImage2, "./output/keypoints_all.dat");
	printf("Done. %d keypoints found.\n", totalKeypoints);

	free(sourceImage);
	free(sourceImage2);
	free(doubledImage);
	//free octaves - should put it here
	return 0;
}
Esempio n. 3
0
////////////////////////////////////////////////////////////////////////////////////////////////
///// ********** PUBLIC METHODS ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
RRSchedule::RRSchedule(int _max_weeks, int _max_times, int _max_courts, int _max_teams, char* _FILENAME, int SKIP_FIRST)
{
    max_weeks = _max_weeks;
    max_times = _max_times;
    max_courts = _max_courts;
    max_teams = _max_teams;
    skip_first = SKIP_FIRST;
    
    
    FILENAME = _FILENAME;
    
    week0 = (skip_first > 0);   // Check if special considerations need to be made for the first week (allowing a meeting)
    
    min_per_night = (max_courts * max_times * 2) / max_teams;
    w0_min_per_night = (max_courts * (max_times-skip_first) * 2) / max_teams;
    
    max_per_night = (max_courts * max_times * 2) / max_teams + ( ((max_courts * max_times * 2) % max_teams) != 0);
    w0_max_per_night = (max_courts * (max_times - skip_first) * 2) / max_teams + ( ((max_courts * (max_times - skip_first) * 2) % max_teams) != 0);
    
    MAX_PLAYED_GAP = 1; // <= Gap between min times played and max times played
    
    if (max_per_night > 2) then:
    {
        MAX_WAIT_TIME = min_per_night;   // <= Max time a team can wait each night
    }
    else
    {
        MAX_WAIT_TIME = min_per_night;
    }
    
    MAX_WAIT_GAP = 1; //*max_times ; // /2;   // <= Gap between min team wait time and max team wait time
    
    MAX_TIMESLOT_GAP = 2 ; //max_weeks / 2; // <=  Gap between count of min timeslot vs. max timeslot appearances
    TIMESLOT_FUDGE = 0; // *max_per_night; // Allow teams to play in a timeslot # over "ideal"
    max_per_time = (max_weeks * max_courts * 2) / max_teams + ( ((max_weeks * max_courts * 2) % max_teams) != 0) + TIMESLOT_FUDGE; //    std::cout << "**" <<std:endl;
    
    
    fullSolution = false;
    total_wait_time = 0;
    
    init1D(this_week_played, max_teams);
    allocate1D(courts, max_courts*2);
    init1D(total_played, max_teams);
    init1D(total_waiting_by_team, max_teams);
    
    init2D(opponent_counts, max_teams, max_teams);
    allocate2D(timeslots, max_times, max_courts*2);
    allocate2D(matchups, max_weeks * max_times * max_courts, 2);
    init2D(this_week_matchups, (max_times-skip_first)*max_courts, 2);
    init2D(timeslots_played, max_teams, max_times);
    init2D(courts_played, max_teams, max_courts);
    allocate2D(timePermutes, FACTS[max_times], max_times);
    compute_permutations();
    allocate2D(total_this_week_played,max_weeks, max_teams);
    
    allocate3D(weeks, max_weeks, max_times, max_courts*2);
    
    
    // clear old file
    std::ofstream outputfile;
    outputfile.open(FILENAME);
    outputfile.close();
}