All Downloads are FREE. Search and download functionalities are using the official Maven repository.

boofcv.abst.feature.describe.DescribeSift_RadiusAngle Maven / Gradle / Ivy

Go to download

BoofCV is an open source Java library for real-time computer vision and robotics applications.

The newest version!
/*
 * Copyright (c) 2021, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package boofcv.abst.feature.describe;

import boofcv.BoofDefaults;
import boofcv.alg.feature.describe.DescribePointSift;
import boofcv.alg.feature.detect.interest.SiftScaleSpace;
import boofcv.alg.feature.detect.interest.UnrollSiftScaleSpaceGradient;
import boofcv.core.image.GConvertImage;
import boofcv.struct.feature.TupleDesc_F64;
import boofcv.struct.image.GrayF32;
import boofcv.struct.image.ImageGray;
import boofcv.struct.image.ImageType;

/**
 * Allows you to use SIFT features independent of the SIFT detector. A SIFT scale-space is computed with all octaves
 * and most of the scales saved. When a few feature is requested it looks up the closest scale image and uses
 * that as the input image.
 *
 * @author Peter Abeles
 */
public class DescribeSift_RadiusAngle>
		implements DescribePointRadiusAngle {
	// expected type of input image. All image types are converted to floats since that's what
	// the scale-space requires
	ImageType imageType;

	// precomputes the entire scale-space gradient for faster lookup later
	UnrollSiftScaleSpaceGradient gradient = new UnrollSiftScaleSpaceGradient();

	SiftScaleSpace scaleSpace;

	// computes the feature description
	DescribePointSift describe;

	// used as temporary storage for the input image if it needs to be converted
	GrayF32 imageFloat = new GrayF32(1, 1);

	public DescribeSift_RadiusAngle( SiftScaleSpace scaleSpace,
									 DescribePointSift describe,
									 Class imageType ) {
		this.scaleSpace = scaleSpace;
		this.describe = describe;
		this.imageType = ImageType.single(imageType);

		gradient.initialize(scaleSpace);
	}

	@Override
	public void setImage( T image ) {
		GrayF32 input;
		if (image instanceof GrayF32) {
			input = (GrayF32)image;
		} else {
			imageFloat.reshape(image.width, image.height);
			GConvertImage.convert(image, imageFloat);
			input = imageFloat;
		}

		scaleSpace.process(input);
		gradient.process(scaleSpace);
	}

	@Override
	public boolean process( double x, double y, double orientation, double radius, TupleDesc_F64 description ) {

		// get the blur sigma for the radius
		double sigma = radius/BoofDefaults.SIFT_SCALE_TO_RADIUS;

		// find the image which the blur factor closest to this sigma
		UnrollSiftScaleSpaceGradient.ImageScale image = gradient.lookup(sigma);

		// compute the descriptor
		describe.setImageGradient(image.derivX, image.derivY);
		describe.process(x/image.imageToInput, y/image.imageToInput, sigma/image.imageToInput,
				orientation, description);

		return true;
	}

	@Override
	public boolean isScalable() {
		return true;
	}

	@Override
	public boolean isOriented() {
		return true;
	}

	@Override
	public ImageType getImageType() {
		return imageType;
	}

	@Override
	public double getCanonicalWidth() {
		return describe.getCanonicalRadius()*2;
	}

	@Override
	public TupleDesc_F64 createDescription() {
		return new TupleDesc_F64(describe.getDescriptorLength());
	}

	@Override
	public Class getDescriptionType() {
		return TupleDesc_F64.class;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy