/** * Creates a circular kernel with width {@code 2*radius + 1}. * The key element is at position {@code x=radius, y=radius}. * * @param radius the radius of the circle expressed in pixels * @param type a {@link ValueType} constant * @param centreValue the value to assign to the kernel centre (key element) * * @return a new {@code KernelJAI} object * * @deprecated Please use {@link #createCircle(int, ValueType)} instead and * set the centre element value on the returned kernel if that is * required. */ public static KernelJAI createCircle(int radius, ValueType type, float centreValue) { KernelJAI kernel = createCircle(radius, type); return KernelUtil.setElement(kernel, radius, radius, centreValue); }
/** * Creates a rectangular kernel where all elements have value 1.0. * The key element will be at {@code (width/2, height/2)}. * * @param width rectangle width * @param height rectangle height * * @return a new {@code KernelJAI} object * * @throws IllegalArgumentException if either {@code width} or {@code height} * are less than 1 */ public static KernelJAI createRectangle(int width, int height) { return createConstantRectangle(width, height, 1.0f); }
/** * Create a circular kernel where all elements within the circle * have value 1.0 while those outside have value 0.0. * Kernel width is {@code 2*radius + 1}. * The key element is at position {@code x=radius, y=radius}. * <p> * This is equivalent to: * <pre><code> * createCircle(radius, Kernel.ValueType.BINARY, 1.0f) * </code></pre> * * @param radius radius of the circle * * @return a new {@code KernelJAI} object */ public static KernelJAI createCircle(int radius) { return createConstantCircle(radius, 1.0f); }
public static KernelJAI createConstantCircle(int radius, float value) { if (radius <= 0) { throw new IllegalArgumentException( "Invalid radius (" + radius + "); must be > 0"); } KernelFactoryHelper helper = new KernelFactoryHelper(); float[] weights = helper.makeCircle(radius); int w = 2*radius + 1; helper.rowFill(weights, w, w, value); return new KernelJAI(w, w, weights); }
/** * Creates a new KernelJAI object with a rectangular configuraton. * An IllegalArgumentException will be thrown if width or height are less than 1. * <p> * This is equivalent to calling... * <p> * {@code createRectangle(width, height, Kernel.ValueType.BINARY, width/2, height/2, 1.0f) } * * @param width rectangle width * @param height rectangle height * * @return a new instance of KernelJAI */ public static KernelJAI createRectangle(int width, int height) { float [] weights = (new KernelFactoryHelper()).makeRect(width, height); return new KernelJAI(width, height, weights); }
return createCircle(outerRadius, type, centreValue); KernelFactoryHelper kh = new KernelFactoryHelper(); float value = 0f; if (kh.fcomp(dist2, outer2) <= 0 && kh.fcomp(dist2, inner2) > 0) { if (type == ValueType.DISTANCE) { value = (float) Math.sqrt(dist2);
KernelFactoryHelper kh = new KernelFactoryHelper(); float value = 0f; if (kh.fcomp(r2, dist2) >= 0) { if (type == ValueType.DISTANCE) { value = (float) Math.sqrt(dist2);
/** * Creates a rectangular kernel. If the element value type is one that involves * proportional distance, such as {@link ValueType#COSINE} or * {@link ValueType#EPANECHNIKOV}, this is calculated as the proportion of the * maximum distance from the key element to a kernel edge element. * * @param width rectangle width * @param height rectangle height * @param type a {@link ValueType} constant * @param keyX X ordinate of the key element * @param keyY Y ordinate of the key element (0 is top) * @param keyValue value of the key element * * @return a new {@code KernelJAI} object * * @throws IllegalArgumentException if either {@code width} or {@code height} * are less than 1; or if {@code keyX} is not in the interval {@code [0,width)}; * or if {@code keyY} is not in the interval {@code [0,height)}; * * @deprecated Please use {@link #createRectangle(int, int, ValueType, int, int)} * instead and set the centre element value on the returned kernel if that is * required. */ public static KernelJAI createRectangle( int width, int height, ValueType type, int keyX, int keyY, float keyValue) { KernelJAI kernel = createRectangle(width, height, type, keyX, keyY); return KernelUtil.setElement(kernel, keyX, keyY, keyValue); }
/** * Creates an annular kernel (a doughnut). * The kernel width is {@code 2*outerRadius + 1}. * The kernel's key element is at position {@code x=outerRadius, y=outerRadius}. * <p> * Calling this method with {@code innerRadius == 0} is equivalent to * calling {@link #createCircle } * * @param outerRadius the radius of the annulus * @param innerRadius the radius of the 'hole' * @param type a {@link ValueType} constant * @param centreValue the value to assign to the kernel centre (key element) * * @return a new {@code KernelJAI} object * * @throws IllegalArgumentException if {@code outerRadius <= 0} or * {@code innerRadius >= outerRadius} * * @deprecated Please use {@link #createAnnulua(int, int, ValueType)} instead and * set the centre element value on the returned kernel if that is * required. */ public static KernelJAI createAnnulus(int outerRadius, int innerRadius, ValueType type, float centreValue) { KernelJAI kernel = createAnnulus(outerRadius, innerRadius, type); return KernelUtil.setElement(kernel, outerRadius, outerRadius, centreValue); }
/** * Create a new KernelJAI object with a circular configuration. * Kernel elements within the circle will have value 1.0f; those * outside will have value 0.0f. * <p> * This is equivalent to, but faster than, calling... * <p> * {@code createCircle(radius, Kernel.ValueType.BINARY, 1.0f) } * * @param radius radius of the circle * @return a new instance of KernelJAI */ public static KernelJAI createCircle(int radius) { if (radius <= 0) { throw new IllegalArgumentException( "Invalid radius (" + radius + "); must be > 0"); } KernelFactoryHelper kh = new KernelFactoryHelper(); float[] weights = kh.makeCircle(radius); int w = 2*radius + 1; kh.rowFill(weights, w, w); return new KernelJAI(w, w, weights); }
/** * Creates a new KernelJAI object with a rectangular configuraton. * An IllegalArgumentException will be thrown if width or height are less than 1. * <p> * This is equivalent to calling... * <p> * {@code createRectangle(width, height, Kernel.ValueType.BINARY, width/2, height/2, 1.0f) } * * @param width rectangle width * @param height rectangle height * * @return a new instance of KernelJAI */ public static KernelJAI createRectangle(int width, int height) { float [] weights = (new KernelFactoryHelper()).makeRect(width, height); return new KernelJAI(width, height, weights); }
return createCircle(outerRadius, type, centreValue); KernelFactoryHelper kh = new KernelFactoryHelper(); float value = 0f; if (kh.fcomp(dist2, outer2) <= 0 && kh.fcomp(dist2, inner2) > 0) { if (type == ValueType.DISTANCE) { value = (float) Math.sqrt(dist2);
KernelFactoryHelper kh = new KernelFactoryHelper(); float value = 0f; if (kh.fcomp(r2, dist2) >= 0) { if (type == ValueType.DISTANCE) { value = (float) Math.sqrt(dist2);
/** * Create a new KernelJAI object with a circular configuration. * Kernel elements within the circle will have value 1.0f; those * outside will have value 0.0f. * <p> * This is equivalent to, but faster than, calling... * <p> * {@code createCircle(radius, Kernel.ValueType.BINARY, 1.0f) } * * @param radius radius of the circle * @return a new instance of KernelJAI */ public static KernelJAI createCircle(int radius) { if (radius <= 0) { throw new IllegalArgumentException( "Invalid radius (" + radius + "); must be > 0"); } KernelFactoryHelper kh = new KernelFactoryHelper(); float[] weights = kh.makeCircle(radius); int w = 2*radius + 1; kh.rowFill(weights, w, w); return new KernelJAI(w, w, weights); }
/** * Creates a rectangular kernel where all elements have the same value. * The key element will be at {@code (width/2, height/2)}. * * @param width rectangle width * @param height rectangle height * @param value element value * * @return a new {@code KernelJAI} object * * @throws IllegalArgumentException if either {@code width} or {@code height} * are less than 1 */ public static KernelJAI createConstantRectangle(int width, int height, float value) { if (width < 1 || height < 1) { throw new IllegalArgumentException("width and height must both be >= 1"); } float [] weights = (new KernelFactoryHelper()).makeRect(width, height, value); return new KernelJAI(width, height, weights); }
/** * Creates a rectangular kernel where all elements have the same value. * * @param width rectangle width * @param height rectangle height * @param value element value * @param keyX key element X ordinate * @param keyY key element Y ordinate * * @return a new {@code KernelJAI} object * * @throws IllegalArgumentException if either {@code width} or {@code height} * are less than 1 or if the key element location is outside the * rectangle */ public static KernelJAI createConstantRectangle(int width, int height, int keyX, int keyY, float value) { if (width < 1 || height < 1) { throw new IllegalArgumentException("width and height must both be >= 1"); } if (keyX < 0 || keyX >= width || keyY < 0 || keyY >= height) { throw new IllegalArgumentException("key element must be within the rectangle"); } float [] weights = (new KernelFactoryHelper()).makeRect(width, height, value); return new KernelJAI(width, height, keyX, keyY, weights); }
KernelFactoryHelper kh = new KernelFactoryHelper(); float weights[]; weights = kh.makeRect(width, height); weights[keyX + keyY*width] = keyValue; return new KernelJAI(width, height, keyX, keyY, weights);
KernelFactoryHelper kh = new KernelFactoryHelper(); float weights[]; weights = kh.makeRect(width, height); weights[keyX + keyY*width] = keyValue; return new KernelJAI(width, height, keyX, keyY, weights);