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

boofcv.alg.interpolate.impl.ImplPolynomialPixel_F32 Maven / Gradle / Ivy

Go to download

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

There is a newer version: 0.26
Show newest version
/*
 * Copyright (c) 2011-2014, 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.alg.interpolate.impl;

import boofcv.alg.interpolate.PolynomialPixel;
import boofcv.struct.image.ImageFloat32;
import boofcv.struct.image.ImageType;

/**
 * 

* Implementation of {@link PolynomialPixel}. *

* * @author Peter Abeles */ public class ImplPolynomialPixel_F32 extends PolynomialPixel { public ImplPolynomialPixel_F32(int maxDegree, float min, float max) { super(maxDegree, min, max); } @Override public float get(float x, float y) { if( x < 0 || y < 0 || x > image.width-1 || y > image.height-1 ) throw new IllegalArgumentException("Pixel out of bounds. "+x+" "+y); int width = image.getWidth(); int height = image.getHeight(); final int xt = (int) x; final int yt = (int) y; // offM makes sure even numbered M will bound the test point with samples int x0 = xt - M/2 + offM; int x1 = x0 + M; int y0 = yt - M/2 + offM; int y1 = y0 + M; if( x0 < 0 ) { x0 = 0;} if( x1 > width) {x1 = width;} if( y0 < 0 ) { y0 = 0;} if( y1 > height) {y1 = height;} final int horizM = x1-x0; final int vertM = y1-y0; interp1D.setInput(horiz,horizM); for( int i = 0; i < vertM; i++ ) { for( int j = 0; j < horizM; j++ ) { horiz[j] = image.get(j+x0,i+y0); } vert[i]=interp1D.process(x-x0,0,horizM-1); } interp1D.setInput(vert,vertM); float ret = interp1D.process(y-y0,0,vertM-1); // because it is fitting polynomials it can go above and below max values. if( ret > max ) { ret = max; } else if( ret < min ) { ret = min; } return ret; } @Override public float get_fast(float x, float y) { int xt = (int) x; int yt = (int) y; int x0 = xt - M/2 + offM; int y0 = yt - M/2 + offM; interp1D.setInput(horiz,horiz.length); for( int i = 0; i < M; i++ ) { for( int j = 0; j < M; j++ ) { horiz[j] = image.get(j+x0,i+y0); } vert[i]=interp1D.process(x-x0,0,M-1); } interp1D.setInput(vert,vert.length); float ret = interp1D.process(y-y0,0,M-1); // because it is fitting polynomials it can go above or below max or min values. if( ret > max ) { ret = max; } else if( ret < min ) { ret = min; } return ret; } @Override public ImageType getImageType() { return ImageType.single(ImageFloat32.class); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy