public OrientationGradientToImage(OrientationGradient<D> alg, ImageGradient<T, D> gradient, Class<T> inputType , Class<D> gradientType ) { this.alg = alg; this.gradient = gradient; this.inputType = inputType; derivX = GeneralizedImageOps.createSingleBand(gradientType,1,1); derivY = GeneralizedImageOps.createSingleBand(gradientType,1,1); }
public static <T extends ImageBase> T createImage(Class<T> type, int width, int height, int numBands ) { if( (Class)type == Planar.class ) throw new IllegalArgumentException("Can't use this function with planar because the data type needs to be specified too"); if( ImageGray.class.isAssignableFrom(type)) return (T)createSingleBand((Class)type,width,height); else if( ImageInterleaved.class.isAssignableFrom(type)) return (T)createInterleaved((Class)type,width,height,numBands); else throw new RuntimeException("Unknown"); } public static <T extends ImageGray<T>> T createSingleBand(Class<T> type, int width, int height) {
/** * Compute SAD (Sum of Absolute Difference) error. * * @param leftX X-axis center left image * @param rightX X-axis center left image * @param centerY Y-axis center for both images * @return Fit score for both regions. */ protected double computeScoreRect( int leftX , int rightX , int centerY ) { double ret=0; for( int y = -radiusY; y <= radiusY; y++ ) { for( int x = -radiusX; x <= radiusX; x++ ) { double l = GeneralizedImageOps.get(imageLeft,leftX+x,centerY+y); double r = GeneralizedImageOps.get(imageRight,rightX+x,centerY+y); ret += Math.abs(l-r); } } return ret; } }
public static <T extends KernelBase> T createKernelForImage( int width , int offset, int DOF , Class imageType ) { boolean isFloat = GeneralizedImageOps.isFloatingPoint(imageType); int numBits = Math.max(32, GeneralizedImageOps.getNumBits(imageType)); return createKernel(width,offset,DOF,isFloat,numBits); }
private static Method findHessian(Class<?> derivativeClass, Class<?> inputType , Class<?> derivType ) { Method m; try { Class<?> borderType = GeneralizedImageOps.isFloatingPoint(inputType) ? ImageBorder_F32.class : ImageBorder_S32.class; m = derivativeClass.getDeclaredMethod("process", inputType,derivType,derivType,derivType,borderType); } catch (NoSuchMethodException e) { throw new RuntimeException("Input and derivative types are probably not compatible",e); } return m; }
public static <T extends ImageInterleaved> T createInterleaved(ImageDataType type, int width, int height , int numBands) { Class<T> typeClass = ImageType.getImageClass(ImageType.Family.INTERLEAVED, type); return (T)createInterleaved(typeClass,width,height,numBands); }
private static Method findDerivative(Class<?> derivativeClass, Class<?> inputType , Class<?> derivType ) { Method m; try { Class<?> borderType = GeneralizedImageOps.isFloatingPoint(inputType) ? ImageBorder_F32.class : ImageBorder_S32.class; m = derivativeClass.getDeclaredMethod("process", inputType,derivType,derivType,borderType); } catch (NoSuchMethodException e) { throw new RuntimeException("Input and derivative types are probably not compatible",e); } return m; }
/** * Creates a 1D Gaussian kernel of the specified type. * * @param imageType The type of image which is to be convolved by this kernel. * @param sigma The distributions stdev. If ≤ 0 then the sigma will be computed from the radius. * @param radius Number of pixels in the kernel's radius. If ≤ 0 then the sigma will be computed from the sigma. * @return The computed Gaussian kernel. */ public static <T extends ImageGray<T>, K extends Kernel1D> K gaussian1D(Class<T> imageType, double sigma, int radius ) { boolean isFloat = GeneralizedImageOps.isFloatingPoint(imageType); int numBits = GeneralizedImageOps.getNumBits(imageType); if( numBits < 32 ) numBits = 32; return gaussian(1,isFloat, numBits, sigma,radius); }
public static <T extends ImageInterleaved<T>>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = (T)GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }
public OrientationIntegralToImage(OrientationIntegral<II> alg, Class<T> inputType , Class<II> integralType ) { this.alg = alg; this.inputType = inputType; integralImage = GeneralizedImageOps.createSingleBand(integralType, 1, 1); }
public FourierVisualizeApp(ImageDataType imageType) { this.imageType = imageType; image = GeneralizedImageOps.createSingleBand(imageType,1,1); transform = GeneralizedImageOps.createInterleaved(imageType, 1, 1, 2); magnitude = GeneralizedImageOps.createSingleBand(imageType,1,1); phase = GeneralizedImageOps.createSingleBand(imageType,1,1); fft = GDiscreteFourierTransformOps.createTransform(imageType); setMainGUI(panel); }
private static Method findHessianFromGradient(Class<?> derivativeClass, Class<?> imageType ) { String name = derivativeClass.getSimpleName().substring(8); Method m; try { Class<?> borderType = GeneralizedImageOps.isFloatingPoint(imageType) ? ImageBorder_F32.class : ImageBorder_S32.class; m = HessianFromGradient.class.getDeclaredMethod("hessian"+name, imageType,imageType,imageType,imageType,imageType,borderType); } catch (NoSuchMethodException e) { throw new RuntimeException("Input and derivative types are probably not compatible",e); } return m; } }
/** * Compute SAD (Sum of Absolute Difference) error. * * @param leftX X-axis center left image * @param rightX X-axis center left image * @param centerY Y-axis center for both images * @return Fit score for both regions. */ protected double computeScore( int leftX , int rightX , int centerY ) { double ret=0; for( int y = -radiusY; y <= radiusY; y++ ) { for( int x = -radiusX; x <= radiusX; x++ ) { double l = GeneralizedImageOps.get(imageLeft,leftX+x,centerY+y); double r = GeneralizedImageOps.get(imageRight,rightX+x,centerY+y); ret += Math.abs(l-r); } } return ret; } }
/** * Creates a 2D Gaussian kernel of the specified type. * * @param imageType The type of image which is to be convolved by this kernel. * @param sigma The distributions stdev. If ≤ 0 then the sigma will be computed from the radius. * @param radius Number of pixels in the kernel's radius. If ≤ 0 then the sigma will be computed from the sigma. * @return The computed Gaussian kernel. */ public static <T extends ImageGray<T>, K extends Kernel2D> K gaussian2D(Class<T> imageType, double sigma, int radius ) { boolean isFloat = GeneralizedImageOps.isFloatingPoint(imageType); int numBits = Math.max(32, GeneralizedImageOps.getNumBits(imageType)); return gaussian(2,isFloat, numBits, sigma,radius); }
public static <T extends ImageInterleaved>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }
public ImplSsdCornerBase( int windowRadius , Class<D2> secondDerivType ) { this.radius = windowRadius; horizXX = GeneralizedImageOps.createSingleBand(secondDerivType,1,1); horizXY = GeneralizedImageOps.createSingleBand(secondDerivType,1,1); horizYY = GeneralizedImageOps.createSingleBand(secondDerivType,1,1); }
/** * Creates a new image. * * @param width Number of columns in the image. * @param height Number of rows in the image. * @return New instance of the image. */ public T createImage( int width , int height ) { switch( family ) { case GRAY: return (T)GeneralizedImageOps.createSingleBand(getImageClass(),width,height); case INTERLEAVED: return (T)GeneralizedImageOps.createInterleaved(getImageClass(), width, height, numBands); case PLANAR: return (T)new Planar(getImageClass(),width,height,numBands); default: throw new IllegalArgumentException("Type not yet supported"); } }
public static <T extends ImageGray<T>, K extends Kernel1D> K derivativeI( Class<T> imageType , int order, double sigma, int radius ) { boolean isFloat = GeneralizedImageOps.isFloatingPoint(imageType); return derivative(order,isFloat,sigma,radius); }
public static double get(ImageBase img, int x, int y , int band ) { if (img instanceof ImageGray) { return get((ImageGray) img, x, y); } else if (img instanceof ImageInterleaved) { return get((ImageInterleaved) img, x, y, band); } else if (img instanceof Planar) { return get(((Planar) img).getBand(band), x, y); } else { throw new IllegalArgumentException("Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
/** * Creates a single band image of the specified type that will have the same * shape as this image */ public <B extends ImageGray<B>> B createSameShape( Class<B> type ) { return GeneralizedImageOps.createSingleBand(type,width,height); }