import java.util.Vector; import Jama.Matrix; /** * Filter Implementation. * Easy Filter V1.0, Copyright E.B/JavaZOOM - 1999. * Using the Jama Matrix Package. * * ========================================================================= * Copyright (C) 1999 by E.B, JavaZOOM All rights reserved. * * Permission to use, copy, modify, and distribute this software is freely * granted by JavaZOOM, provided that the copyright notice * above and the following warranty disclaimer are preserved in human * readable form. * * Because this software is licenses free of charge, it is provided * "AS IS", with NO WARRANTY. TO THE EXTENT PERMITTED BY LAW, JavaZOOM * DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO ITS PERFORMANCE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * JavaZOOM WILL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING OUT OF THE USE * OF OR INABILITY TO USE THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, PUNITIVE, AND EXEMPLARY DAMAGES, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * ========================================================================= */ public class FilterImplementation extends GenericFilter { /** * FilterImplementation Constructor. * Do not modify ! */ public FilterImplementation(Vector paramsValue,int[] imageArray,int imgWidth, int imgHeight) { super(paramsValue,imageArray,imgWidth,imgHeight); } /** * Gradient Computation based on Philippe Paillou article. * IEEE Trans. Geo. & Remote Sensing VOL 35 No.1 Jan. 1997. * It uses sigma,lamda,k (Canny's criteria) through c,alpha,w parameters. */ public void computeFilter() { /*-- Images parameters --*/ int[] source = getInitialImageBuffer(); int samples = getInitialImageWidth(); int lines = getInitialImageHeight(); /*-- Set Output Data --*/ setFinalImageWidth(samples); setFinalImageHeight(lines); int[] target = new int[samples*lines]; setFinalImageBuffer(target); /*-- Get GUI Parameters --*/ double alpha = getParamValue(0); double w = getParamValue(1); /*-- Filter Red Component only (coz greyscale image) --*/ int[] sourceR = new int[lines*samples]; for (int loc=0;locMaxi) Maxi = Ifinal[i][j]; if (Ifinal[i][j]= 0; i--) { b2 = b1; b1 = b0; b0 = twox*b1 - b2 + coef[i]; } return 0.5*(b0-b2); } private static final double SINH_COEF[] = { 0.1730421940471796, 0.08759422192276048, 0.00107947777456713, 0.00000637484926075, 0.00000002202366404, 0.00000000004987940, 0.00000000000007973, 0.00000000000000009}; /** * Returns the inverse (arc) hyperbolic sine of a double. * @param x A double value. * @return The arc hyperbolic sine of x. * If x is NaN or less than one, the result is NaN. */ static public double sinh(double x) { double ans; double y = Math.abs(x); if (Double.isNaN(x)) { ans = Double.NaN; } else if (Double.isInfinite(y)) { return x; } else if (y < 2.58096e-08) { // 2.58096e-08 = Math.sqrt(6.0*EPSILON_SMALL) ans = x; } else if (y <= 1.0) { ans = x*(1.0+csevl(2.0*x*x-1.0,SINH_COEF)); } else { y = Math.exp(y); if (y >= 94906265.62) { // 94906265.62 = 1.0/Math.sqrt(EPSILON_SMALL) ans = sign(0.5*y,x); } else { ans = sign(0.5*(y-1.0/y),x); } } return ans; } /** * Returns the hyperbolic cosine of a double. * @param x A double value. * @return The hyperbolic cosine of x. * If x is NaN, the result is NaN. */ static public double cosh(double x) { double ans; double y = Math.exp(Math.abs(x)); if (Double.isNaN(x)) { ans = Double.NaN; } else if (Double.isInfinite(x)) { ans = x; } else if (y < 94906265.62) { // 94906265.62 = 1.0/Math.sqrt(EPSILON_SMALL) ans = 0.5*(y+1.0/y); } else { ans = 0.5*y; } return ans; } }