void ComputeHarrisFeatures(CFloatImage &image, FeatureSet &features)
{
    //Create grayscale image used for Harris detection
    CFloatImage grayImage=ConvertToGray(image);

    //Create image to store Harris values
    CFloatImage harrisImage(image.Shape().width,image.Shape().height,1);

    //Create image to store local maximum harris values as 1, other pixels 0
    CByteImage harrisMaxImage(image.Shape().width,image.Shape().height,1);

    //compute Harris values puts harris values at each pixel position in harrisImage. 
    //You'll need to implement this function.
    computeHarrisValues(grayImage, harrisImage);
        
    // Threshold the harris image and compute local maxima.  You'll need to implement this function.
    computeLocalMaxima(harrisImage,harrisMaxImage);

    // Prints out the harris image for debugging purposes
    CByteImage tmp(harrisImage.Shape());
    convertToByteImage(harrisImage, tmp);
    WriteFile(tmp, "harris.tga");

    // TO DO--------------------------------------------------------------------
    //Loop through feature points in harrisMaxImage and fill in information needed for 
    //descriptor computation for each point above a threshold. We fill in id, type, 
    //x, y, and angle.
	CFloatImage A(grayImage.Shape());
	CFloatImage B(grayImage.Shape());
	CFloatImage C(grayImage.Shape());

	CFloatImage partialX(grayImage.Shape());
	CFloatImage partialY(grayImage.Shape());

	GetHarrisComponents(grayImage, A, B, C, &partialX, &partialY);
	int featureCount = 0;
    for (int y=0;y<harrisMaxImage.Shape().height;y++) {
        for (int x=0;x<harrisMaxImage.Shape().width;x++) {
                
            // Skip over non-maxima
            if (harrisMaxImage.Pixel(x, y, 0) == 0)
				continue;

            //TO DO---------------------------------------------------------------------
            // Fill in feature with descriptor data here. 
            Feature f;
			f.type = 2;
			f.id = featureCount++;
			f.x = x;
			f.y = y;
			f.angleRadians = GetCanonicalOrientation(x, y, A, B, C, partialX, partialY);
				//atan(partialY.Pixel(x, y, 0)/partialX.Pixel(x, y, 0));
			// Add the feature to the list of features
            features.push_back(f);
        }
    }
}
Esempio n. 2
0
// Compute features using Harris corner detection method
void ComputeHarrisFeatures(CFloatImage &image, FeatureSet &features)
{
	// Create grayscale image used for Harris detection
	CFloatImage grayImage = ConvertToGray(image);

	// Create image to store Harris values
	CFloatImage harrisImage(image.Shape().width,image.Shape().height,1);

	// Create image to store local maximum harris values as 1, other pixels 0
	CByteImage harrisMaxImage(image.Shape().width,image.Shape().height,1);

	// Create image to store orientation values
	CFloatImage orientationImage(image.Shape().width, image.Shape().height, 1);

	// Compute the harris score at each pixel position, storing the result in in harrisImage. 
	computeHarrisValues(grayImage, harrisImage, orientationImage);

	// Threshold the harris image and compute local maxima.
	computeLocalMaxima(harrisImage,harrisMaxImage);

	// Save images
	CByteImage tmp(harrisImage.Shape());
	CByteImage tmp2(harrisImage.Shape());
	convertToByteImage(harrisImage, tmp);
	convertToByteImage(grayImage, tmp2);
	WriteFile(tmp2, "grayImg.tga");
	WriteFile(tmp, "harris.tga");
	WriteFile(harrisMaxImage, "harrisMax.tga");

	// Loop through feature points in harrisMaxImage and fill in id, type, x, y, and angle 
	// information needed for descriptor computation for each feature point, then add them
	// to feature set
	int id = 0;
	for (int y=0; y < harrisMaxImage.Shape().height; y++) {
		for (int x=0; x < harrisMaxImage.Shape().width; x++) {
			if (harrisMaxImage.Pixel(x, y, 0) == 1) {
				Feature f;
				f.id = id;
				f.type = 2;
				f.x = x;
				f.y = y;
				f.angleRadians = orientationImage.Pixel(x,y,0);
				
				features.push_back(f);
				id++;
			}
		}
	}
}