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; }
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; }
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; } }
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 <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); }
public static <T extends ImageGray<T>, K extends Kernel2D> ImageConvolveSparse<T,K> convolve2D(Class<T> imageType, K kernel) { if( GeneralizedImageOps.isFloatingPoint(imageType)) { return (ImageConvolveSparse<T,K>)new Convolve2D_F32((Kernel2D_F32)kernel); } else { return (ImageConvolveSparse<T,K>)new Convolve2D_I32((Kernel2D_S32)kernel); } }
public static <T extends ImageGray<T>, K extends Kernel1D> ImageConvolveSparse<T,K> horizontal1D(Class<T> imageType, K kernel) { if( GeneralizedImageOps.isFloatingPoint(imageType)) { return (ImageConvolveSparse<T,K>)new Horizontal1D_F32((Kernel1D_F32)kernel); } else { return (ImageConvolveSparse<T,K>)new Horizontal1D_I32((Kernel1D_S32)kernel); } }
/** * 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 ImageGray<T>, K extends Kernel1D> ImageConvolveSparse<T,K> vertical1D(Class<T> imageType, K kernel) { if( GeneralizedImageOps.isFloatingPoint(imageType)) { return (ImageConvolveSparse<T,K>)new Vertical1D_F32((Kernel1D_F32)kernel); } else { return (ImageConvolveSparse<T,K>)new Vertical1D_I32((Kernel1D_S32)kernel); } }
/** * 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); }
/** * <p> * Convenience function for creating an instance of {@link boofcv.abst.filter.derivative.AnyImageDerivative}. * This class is an any way to compute any derivative of any order using the specified kernel. It might * use more memory or be more expensive the specialized code but is easy to use. * </p> * * @param type Type of gradient to use * @param inputType Type of input image. * @param derivType Type of derivative image * @param <I> Image type. * @param <D> Image derivative type. * @return AnyImageDerivative */ public static <I extends ImageGray<I>, D extends ImageGray<D>> AnyImageDerivative<I,D> createAnyDerivatives( DerivativeType type , Class<I> inputType , Class<D> derivType ) { boolean isInteger = !GeneralizedImageOps.isFloatingPoint(inputType); KernelBase kernel = lookupKernelX(type,isInteger); if( kernel instanceof Kernel1D ) return new AnyImageDerivative<>((Kernel1D) kernel, inputType, derivType); else return new AnyImageDerivative<>((Kernel2D) kernel, inputType, derivType); }
/** * Constructor which specifies the input image type. * * @param imageType Either {@link GrayU8} or {@link GrayF32} */ public TldVarianceFilter( Class<T> imageType ) { // declare integral images. if(GeneralizedImageOps.isFloatingPoint(imageType) ) { integral = new GrayF32(1,1); integralSq = new GrayF64(1,1); } else { integral = new GrayS32(1,1); integralSq = new GrayS64(1,1); } }
/** * Creates a sparse Laplacian filter. * * @see boofcv.alg.filter.derivative.LaplacianEdge * * @param imageType The type of image which is to be processed. * @param border How the border should be handled. If null {@link BorderType#EXTENDED} will be used. * @return Filter for performing a sparse laplacian. */ public static <T extends ImageGray<T>> ImageFunctionSparse<T> createLaplacian( Class<T> imageType , ImageBorder<T> border ) { if( border == null ) { border = FactoryImageBorder.single(imageType, BorderType.EXTENDED); } if( GeneralizedImageOps.isFloatingPoint(imageType)) { ImageConvolveSparse<GrayF32, Kernel2D_F32> r = FactoryConvolveSparse.convolve2D(GrayF32.class, LaplacianEdge.kernel_F32); r.setImageBorder((ImageBorder_F32)border); return (ImageFunctionSparse<T>)r; } else { ImageConvolveSparse r = FactoryConvolveSparse.convolve2D(GrayI.class, LaplacianEdge.kernel_I32); r.setImageBorder(border); return (ImageFunctionSparse<T>)r; } }
public IntensityPointFeatureApp( List<String> examples , Class<T> imageType ) { super(true,true,examples,ImageType.single(imageType)); this.imageType = imageType; boolean isInteger = !GeneralizedImageOps.isFloatingPoint(imageType); derivType = GImageDerivativeOps.getDerivativeType(imageType); deriv = new AnyImageDerivative<>(GradientThree.getKernelX(isInteger), imageType, derivType); controlPanel = new ControlPanel(); controlPanel.comboAlgorithm.setSelectedIndex(0); add(BorderLayout.WEST,controlPanel); add(BorderLayout.CENTER,imagePanel); imagePanel.addMouseWheelListener(new MouseAdapter() { @Override public void mouseWheelMoved(MouseWheelEvent e) { double curr =imagePanel.getScale(); if( e.getWheelRotation() > 0 ) curr *= 1.1; else curr /= 1.1; imagePanel.setScale(curr); } }); }