Example usage for java.lang Math abs

List of usage examples for java.lang Math abs

Introduction

In this page you can find the example usage for java.lang Math abs.

Prototype

@HotSpotIntrinsicCandidate
public static double abs(double a) 

Source Link

Document

Returns the absolute value of a double value.

Usage

From source file:Main.java

/** This function performs a polynomial interpolation using a set of
 * given x and y values. It uses Neville's interpolation algorithm.
 * @param xa the array of known x-values
 * @param ya the array of known y-values
 * @param x the x value for which the y value will be computed
 * @return the corresponding y value/* w  ww. ja  v a2 s  .  c om*/
 */
public static double interpolate(double xa[], double ya[], double x) {
    /*
    Given arrays xa[1..n] and ya[1..n], and given a value x, 
    this routine returns a value y. 
    If P(x) is the polynomial of degree N ? 1 
    such that P(xa[i]) = ya[i]; 
    i = 1...n, then the returned value y = P(x).
     */

    if (xa.length != ya.length || xa.length == 0 || ya.length == 0) {
        System.out.println("** Invalid Parameter");
        return Double.NaN;
    }

    int n = xa.length;
    double y = 0.0;
    double dy = 0.0;

    int i, m, ns = 1;
    double den, dif, dift, ho, hp, w;
    double[] c = new double[n];
    double[] d = new double[n];
    dif = Math.abs(x - xa[0]);

    for (i = 0; i < n; i++) { // Here we find the index ns of the closest table entry,
        if ((dift = Math.abs(x - xa[i])) < dif) {
            ns = i;
            dif = dift;
        }
        c[i] = ya[i]; // and initialize the tableau of c's and d's.
        d[i] = ya[i];
    }

    y = ya[ns--]; // This is the initial approximation to y.
    //System.out.println("** y ~ "+y);

    for (m = 0; m < n - 1; m++) { // For each column of the tableau,
        for (i = 0; i < n - m - 1; i++) { // we loop over the current c's and d's and update them. 

            //System.out.println("** m = "+m+", i = "+i);
            ho = xa[i] - x;
            hp = xa[i + m + 1] - x;
            w = c[i + 1] - d[i];

            if ((den = ho - hp) == 0.0) {
                return Double.NaN;
            }
            // This error can occur only if two input xa's are (to within roundof identical.

            //System.out.println("** ho = "+ho+", hp = "+hp);

            den = w / den;
            d[i] = hp * den; // Here the c's and d's are updated.
            c[i] = ho * den;
            //System.out.println("** c[i] = "+c[i]+", d[i] = "+d[i]);
        }

        y += (dy = (2 * (ns + 1) < (n - m) ? c[ns + 1] : d[ns--]));
        //System.out.println("** dy = "+dy+", y = "+y);

        /*
        After each column in the tableau is completed, we decide which correction, c or d,
        we want to add to our accumulating value of y, i.e., which path to take through the
        tableau forking up or down. We do this in such a way as to take the most "straight
        line" route through the tableau to its apex, updating ns accordingly to keep track of
        where we are. This route keeps the partial approximations centered (insofar as possible)
        on the target x. The last dy added is thus the error indication.
         */
    }

    return y;
}

From source file:Main.java

/**
 * Returns a transformation matrix from one reference frame into another.
 * Handles cropping (if maintaining aspect ratio is desired) and rotation.
 *
 * @param srcWidth Width of source frame.
 * @param srcHeight Height of source frame.
 * @param dstWidth Width of destination frame.
 * @param dstHeight Height of destination frame.
 * @param applyRotation Amount of rotation to apply from one frame to another.
 *  Must be a multiple of 90.//w  w w  . ja v a 2 s  . co  m
 * @param maintainAspectRatio If true, will ensure that scaling in x and y remains constant,
 * cropping the image if necessary.
 * @return The transformation fulfilling the desired requirements.
 */
public static Matrix getTransformationMatrix(final int srcWidth, final int srcHeight, final int dstWidth,
        final int dstHeight, final int applyRotation, final boolean maintainAspectRatio) {
    final Matrix matrix = new Matrix();

    if (applyRotation != 0) {
        // Translate so center of image is at origin.
        matrix.postTranslate(-srcWidth / 2.0f, -srcHeight / 2.0f);

        // Rotate around origin.
        matrix.postRotate(applyRotation);
    }

    // Account for the already applied rotation, if any, and then determine how
    // much scaling is needed for each axis.
    final boolean transpose = (Math.abs(applyRotation) + 90) % 180 == 0;

    final int inWidth = transpose ? srcHeight : srcWidth;
    final int inHeight = transpose ? srcWidth : srcHeight;

    // Apply scaling if necessary.
    if (inWidth != dstWidth || inHeight != dstHeight) {
        final float scaleFactorX = dstWidth / (float) inWidth;
        final float scaleFactorY = dstHeight / (float) inHeight;

        if (maintainAspectRatio) {
            // Scale by minimum factor so that dst is filled completely while
            // maintaining the aspect ratio. Some image may fall off the edge.
            final float scaleFactor = Math.max(scaleFactorX, scaleFactorY);
            matrix.postScale(scaleFactor, scaleFactor);
        } else {
            // Scale exactly to fill dst from src.
            matrix.postScale(scaleFactorX, scaleFactorY);
        }
    }

    if (applyRotation != 0) {
        // Translate back from origin centered reference to destination frame.
        matrix.postTranslate(dstWidth / 2.0f, dstHeight / 2.0f);
    }

    return matrix;
}

From source file:main.java.utils.Utility.java

public static int getBase(int x) {
    int value = Math.abs(x);

    if (value == 0)
        return 1;
    else/*from w ww.  j a v a2  s.  c o m*/
        return (int) (1 + Math.floor((Math.log(value) / Math.log(10.0d))));
}

From source file:Main.java

/**
 * Returns <code>true</code> if the argument is a finite
 * floating-point value; returns <code>false</code> otherwise (for
 * NaN and infinity arguments).// w  ww . j a  va  2 s  . c o  m
 *
 * @param f the <code>float</code> value to be tested
 * @return <code>true</code> if the argument is a finite
 * floating-point value, <code>false</code> otherwise.
 */
public static boolean isFinite(float f) {
    return Math.abs(f) <= FloatConsts.MAX_VALUE;
}

From source file:com.cloudera.oryx.kmeans.computation.covariance.CoMoment.java

private static boolean approx(double a, double b) {
    return Math.abs(a - b) < 1.0e-6;
}

From source file:com.opengamma.analytics.financial.timeseries.filter.SpikeDoubleTimeSeriesFilter.java

public SpikeDoubleTimeSeriesFilter(final double maxPercentageMove) {
    if (maxPercentageMove < 0) {
        s_logger.info("Maximum percentage move must be positive; using absolute value");
    }/*from  ww w. j a va 2s.  c  o m*/
    _maxPercentageMove = Math.abs(maxPercentageMove);
}

From source file:ID.java

public static long generateLong() {
    return Math.abs(RANDOM1.nextLong() ^ RANDOM2.nextLong() ^ RANDOM3.nextLong());
}

From source file:discovery.compression.kdd2011.ratio.RatioCompressionReport.java

public static void main(String[] args) throws GraphReadingException, IOException, java.text.ParseException {
    opts.addOption("r", true, "Goal compression ratio");

    //      opts.addOption( "a",
    //       true,
    //       "Algorithm used for compression. The default and only currently available option is \"greedy\"");
    //opts.addOption("cost-output",true,"Output file for costs, default is costs.txt");
    //opts.addOption("cost-format",true,"Output format for ");

    opts.addOption("ctype", true, "Connectivity type: global or local, default is global.");
    opts.addOption("connectivity", false,
            "enables output for connectivity. Connectivity info will be written to connectivity.txt");
    opts.addOption("output_bmg", true, "Write bmg file with groups to given file.");
    opts.addOption("algorithm", true, "Algorithm to use, one of: greedy random1 random2 bruteforce slowgreedy");
    opts.addOption("hop2", false, "Only try to merge nodes that have common neighbors");
    opts.addOption("kmedoids", false, "Enables output for kmedoids clustering");
    opts.addOption("kmedoids_k", true, "Number of clusters to be used in kmedoids. Default is 3");
    opts.addOption("kmedoids_output", true,
            "Output file for kmedoid clusters. Default is clusters.txt. This file will be overwritten.");
    opts.addOption("norefresh", false,
            "Use old style merging: all connectivities are not refreshed when merging");
    opts.addOption("edge_attribute", true, "Attribute from bmgraph used as edge weight");
    opts.addOption("only_times", false, "Only write times.txt");
    //opts.addOption("no_metrics",false,"Exit after compression, don't calculate any metrics or produce output bmg for the compression.");
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;/* w  w  w  .  j  a  va  2 s  .com*/

    try {
        cmd = parser.parse(opts, args);
    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(0);
    }

    boolean connectivity = false;
    double ratio = 0;

    boolean hop2 = cmd.hasOption("hop2");

    RatioCompression compression = new GreedyRatioCompression(hop2);

    if (cmd.hasOption("connectivity"))
        connectivity = true;

    ConnectivityType ctype = ConnectivityType.GLOBAL;
    CompressionMergeModel mergeModel = new PathAverageMergeModel();
    if (cmd.hasOption("ctype")) {
        String ctypeStr = cmd.getOptionValue("ctype");
        if (ctypeStr.equals("local")) {
            ctype = ConnectivityType.LOCAL;
            mergeModel = new EdgeAverageMergeModel();
        } else if (ctypeStr.equals("global")) {
            ctype = ConnectivityType.GLOBAL;
            mergeModel = new PathAverageMergeModel();
        } else {
            System.out.println(PROGRAM_NAME + ": unknown connectivity type " + ctypeStr);
            printHelp();
        }
    }

    if (cmd.hasOption("norefresh"))
        mergeModel = new PathAverageMergeModelNorefresh();
    if (cmd.hasOption("algorithm")) {
        String alg = cmd.getOptionValue("algorithm");
        if (alg.equals("greedy")) {
            compression = new GreedyRatioCompression(hop2);
        } else if (alg.equals("random1")) {
            compression = new RandomRatioCompression(hop2);
        } else if (alg.equals("random2")) {
            compression = new SmartRandomRatioCompression(hop2);
        } else if (alg.equals("bruteforce")) {
            compression = new BruteForceCompression(hop2, ctype == ConnectivityType.LOCAL);
        } else if (alg.equals("slowgreedy")) {
            compression = new SlowGreedyRatioCompression(hop2);
        } else {
            System.out.println("algorithm must be one of: greedy random1 random2 bruteforce slowgreedy");
            printHelp();
        }
    }

    compression.setMergeModel(mergeModel);

    if (cmd.hasOption("r")) {
        ratio = Double.parseDouble(cmd.getOptionValue("r"));
    } else {
        System.out.println(PROGRAM_NAME + ": compression ratio not defined");
        printHelp();
    }

    if (cmd.hasOption("help")) {
        printHelp();
    }

    String infile = null;
    if (cmd.getArgs().length != 0) {
        infile = cmd.getArgs()[0];
    } else {
        printHelp();
    }

    boolean kmedoids = false;
    int kmedoidsK = 3;
    String kmedoidsOutput = "clusters.txt";
    if (cmd.hasOption("kmedoids"))
        kmedoids = true;
    if (cmd.hasOption("kmedoids_k"))
        kmedoidsK = Integer.parseInt(cmd.getOptionValue("kmedoids_k"));
    if (cmd.hasOption("kmedoids_output"))
        kmedoidsOutput = cmd.getOptionValue("kmedoids_output");

    String edgeAttrib = "goodness";
    if (cmd.hasOption("edge_attribute"))
        edgeAttrib = cmd.getOptionValue("edge_attribute");

    // This program should directly use bmgraph-java to read and
    // DefaultGraph should have a constructor that takes a BMGraph as an
    // argument.

    //VisualGraph vg = new VisualGraph(infile, edgeAttrib, false);
    //System.out.println("vg read");
    //SimpleVisualGraph origSG = new SimpleVisualGraph(vg);
    BMGraph bmg = BMGraphUtils.readBMGraph(infile);

    int origN = bmg.getNodes().size();

    //for(int i=0;i<origN;i++)
    //System.out.println(i+"="+origSG.getVisualNode(i));
    System.out.println("bmgraph read");

    BMNode[] i2n = new BMNode[origN];
    HashMap<BMNode, Integer> n2i = new HashMap<BMNode, Integer>();
    {
        int pi = 0;
        for (BMNode nod : bmg.getNodes()) {
            n2i.put(nod, pi);
            i2n[pi++] = nod;
        }
    }

    DefaultGraph dg = new DefaultGraph();
    for (BMEdge e : bmg.getEdges()) {
        dg.addEdge(n2i.get(e.getSource()), n2i.get(e.getTarget()), Double.parseDouble(e.get(edgeAttrib)));
    }

    DefaultGraph origDG = dg.copy();

    System.out.println("inputs read");
    RatioCompression nopCompressor = new RatioCompression.DefaultRatioCompression();
    ResultGraph nopResult = nopCompressor.compressGraph(dg, 1);

    long start = System.currentTimeMillis();
    ResultGraph result = compression.compressGraph(dg, ratio);
    long timeSpent = System.currentTimeMillis() - start;
    double seconds = timeSpent * 0.001;

    BufferedWriter timesWriter = new BufferedWriter(new FileWriter("times.txt", true));
    timesWriter.append("" + seconds + "\n");
    timesWriter.close();

    if (cmd.hasOption("only_times")) {
        System.out.println("Compression done, exiting.");
        System.exit(0);
    }

    BufferedWriter costsWriter = new BufferedWriter(new FileWriter("costs.txt", true));
    costsWriter.append("" + nopResult.getCompressorCosts() + " " + result.getCompressorCosts() + "\n");
    costsWriter.close();

    double[][] origProb;
    double[][] compProb;
    int[] group = new int[origN];

    for (int i = 0; i < result.partition.size(); i++)
        for (int x : result.partition.get(i))
            group[x] = i;

    if (ctype == ConnectivityType.LOCAL) {
        origProb = new double[origN][origN];
        compProb = new double[origN][origN];
        DefaultGraph g = result.uncompressedGraph();
        for (int i = 0; i < origN; i++) {
            for (int j = 0; j < origN; j++) {
                origProb[i][j] = dg.getEdgeWeight(i, j);
                compProb[i][j] = g.getEdgeWeight(i, j);
            }
        }
        System.out.println("Writing edge-dissimilarity");
    } else {

        origProb = ProbDijkstra.getProbMatrix(origDG);

        compProb = new double[origN][origN];

        System.out.println("nodeCount = " + result.graph.getNodeCount());
        double[][] ccProb = ProbDijkstra.getProbMatrix(result.graph);
        System.out.println("ccProb.length = " + ccProb.length);

        System.out.println("ccProb[0].length = " + ccProb[0].length);

        for (int i = 0; i < origN; i++) {
            for (int j = 0; j < origN; j++) {
                if (group[i] == group[j])
                    compProb[i][j] = result.graph.getEdgeWeight(group[i], group[j]);
                else {
                    int gj = group[j];
                    int gi = group[i];
                    compProb[i][j] = ccProb[group[i]][group[j]];
                }
            }
        }

        System.out.println("Writing best-path-dissimilarity");
        //compProb = ProbDijkstra.getProbMatrix(result.uncompressedGraph());

    }

    {
        BufferedWriter connWr = null;//

        if (connectivity) {
            connWr = new BufferedWriter(new FileWriter("connectivity.txt", true));
        }
        double totalDiff = 0;

        for (int i = 0; i < origN; i++) {
            for (int j = i + 1; j < origN; j++) {

                double diff = Math.abs(origProb[i][j] - compProb[i][j]);
                //VisualNode ni = origSG.getVisualNode(i);
                //VisualNode nj = origSG.getVisualNode(j);
                BMNode ni = i2n[i];
                BMNode nj = i2n[j];
                if (connectivity)
                    connWr.append(ni + "\t" + nj + "\t" + origProb[i][j] + "\t" + compProb[i][j] + "\t" + diff
                            + "\n");
                totalDiff += diff * diff;
            }
        }

        if (connectivity) {
            connWr.append("\n");
            connWr.close();
        }

        totalDiff = Math.sqrt(totalDiff);
        BufferedWriter dissWr = new BufferedWriter(new FileWriter("dissimilarity.txt", true));
        dissWr.append("" + totalDiff + "\n");
        dissWr.close();
    }

    if (cmd.hasOption("output_bmg")) {
        BMGraph outgraph = new BMGraph();

        String outputfile = cmd.getOptionValue("output_bmg");
        HashMap<Integer, BMNode> nodes = new HashMap<Integer, BMNode>();

        for (int i = 0; i < result.partition.size(); i++) {
            ArrayList<Integer> g = result.partition.get(i);
            if (g.size() == 0)
                continue;
            BMNode node = new BMNode("Supernode_" + i);
            HashMap<String, String> attributes = new HashMap<String, String>();
            StringBuffer contents = new StringBuffer();
            for (int x : g)
                contents.append(i2n[x] + ",");
            contents.delete(contents.length() - 1, contents.length());

            attributes.put("nodes", contents.toString());
            attributes.put("self-edge", "" + result.graph.getEdgeWeight(i, i));
            node.setAttributes(attributes);
            nodes.put(i, node);
            outgraph.ensureHasNode(node);
        }

        for (int i = 0; i < result.partition.size(); i++) {
            if (result.partition.get(i).size() == 0)
                continue;
            for (int x : result.graph.getNeighbors(i)) {
                if (x < i)
                    continue;
                BMNode from = nodes.get(i);
                BMNode to = nodes.get(x);
                if (from == null || to == null) {
                    System.out.println(from + "->" + to);
                    System.out.println(i + "->" + x);
                    System.out.println("");
                }
                BMEdge e = new BMEdge(nodes.get(i), nodes.get(x), "notype");

                e.setAttributes(new HashMap<String, String>());
                e.put("goodness", "" + result.graph.getEdgeWeight(i, x));
                outgraph.ensureHasEdge(e);
            }
        }
        BMGraphUtils.writeBMGraph(outgraph, outputfile);
    }

    // k medoids!
    if (kmedoids) {
        //KMedoidsResult clustersOrig=KMedoids.runKMedoids(origProb,kmedoidsK);

        if (ctype == ConnectivityType.LOCAL) {
            compProb = ProbDijkstra.getProbMatrix(result.uncompressedGraph());
        }

        //KMedoidsResult compClusters = KMedoids.runKMedoids(ProbDijkstra.getProbMatrix(result.graph),kmedoidsK);
        KMedoidsResult clustersComp = KMedoids.runKMedoids(compProb, kmedoidsK);

        BufferedWriter bw = new BufferedWriter(new FileWriter(kmedoidsOutput));

        for (int i = 0; i < origN; i++) {
            int g = group[i];
            //bw.append(origSG.getVisualNode(i).getBMNode()+" "+compClusters.clusters[g]+"\n");
            bw.append(i2n[i] + " " + clustersComp.clusters[i] + "\n");
        }
        bw.close();
    }

    System.exit(0);
}

From source file:com.opengamma.analytics.math.statistics.descriptive.ModeCalculator.java

/**
 * @param x The array of data, not null or empty
 * @return The arithmetic mean// w  w  w  . j  av  a 2s  . c  o m
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length > 0, "x cannot be empty");
    if (x.length == 1) {
        return x[0];
    }
    final double[] x1 = Arrays.copyOf(x, x.length);
    Arrays.sort(x1);
    final TreeMap<Integer, Double> counts = new TreeMap<Integer, Double>();
    int count = 1;
    for (int i = 1; i < x1.length; i++) {
        if (Math.abs(x1[i] - x1[i - 1]) < EPS) {
            count++;
        } else {
            counts.put(count, x1[i - 1]);
            count = 1;
        }
    }
    if (counts.lastKey() == 1) {
        throw new MathException("Could not find mode for array; no repeated values");
    }
    return counts.lastEntry().getValue();
}

From source file:Main.java

public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) {
    Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    if (radius < 1) {
        return (null);
    }//from   w w  w  .  j av a  2 s  .  co m
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] pix = new int[w * h];
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);
    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;

    int vmin[] = new int[Math.max(w, h)];
    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int temp = 256 * divsum;
    int dv[] = new int[temp];
    for (i = 0; i < temp; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];

    int stackpointer;

    int stackstart;

    int[] sir;

    int rbs;

    int r1 = radius + 1;

    int routsum, goutsum, boutsum;

    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {

        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;

        for (i = -radius; i <= radius; i++) {

            p = pix[yi + Math.min(wm, Math.max(i, 0))];

            sir = stack[i + radius];

            sir[0] = (p & 0xff0000) >> 16;

            sir[1] = (p & 0x00ff00) >> 8;

            sir[2] = (p & 0x0000ff);

            rbs = r1 - Math.abs(i);

            rsum += sir[0] * rbs;

            gsum += sir[1] * rbs;

            bsum += sir[2] * rbs;

            if (i > 0) {

                rinsum += sir[0];

                ginsum += sir[1];

                binsum += sir[2];

            } else {

                routsum += sir[0];

                goutsum += sir[1];

                boutsum += sir[2];

            }

        }

        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];

            g[yi] = dv[gsum];

            b[yi] = dv[bsum];

            rsum -= routsum;

            gsum -= goutsum;

            bsum -= boutsum;

            stackstart = stackpointer - radius + div;

            sir = stack[stackstart % div];

            routsum -= sir[0];

            goutsum -= sir[1];

            boutsum -= sir[2];

            if (y == 0) {

                vmin[x] = Math.min(x + radius + 1, wm);

            }

            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;

            sir[1] = (p & 0x00ff00) >> 8;

            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];

            ginsum += sir[1];

            binsum += sir[2];

            rsum += rinsum;

            gsum += ginsum;

            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;

            sir = stack[(stackpointer) % div];

            routsum += sir[0];

            goutsum += sir[1];

            boutsum += sir[2];

            rinsum -= sir[0];

            ginsum -= sir[1];

            binsum -= sir[2];

            yi++;

        }

        yw += w;

    }

    for (x = 0; x < w; x++) {

        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;

        yp = -radius * w;

        for (i = -radius; i <= radius; i++) {

            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];

            sir[1] = g[yi];

            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;

            gsum += g[yi] * rbs;

            bsum += b[yi] * rbs;

            if (i > 0) {

                rinsum += sir[0];

                ginsum += sir[1];

                binsum += sir[2];

            } else {

                routsum += sir[0];

                goutsum += sir[1];

                boutsum += sir[2];

            }

            if (i < hm) {

                yp += w;

            }

        }

        yi = x;

        stackpointer = radius;

        for (y = 0; y < h; y++) {

            pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16)

                    | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;

            gsum -= goutsum;

            bsum -= boutsum;

            stackstart = stackpointer - radius + div;

            sir = stack[stackstart % div];

            routsum -= sir[0];

            goutsum -= sir[1];

            boutsum -= sir[2];

            if (x == 0) {

                vmin[y] = Math.min(y + r1, hm) * w;

            }

            p = x + vmin[y];

            sir[0] = r[p];

            sir[1] = g[p];

            sir[2] = b[p];

            rinsum += sir[0];

            ginsum += sir[1];

            binsum += sir[2];

            rsum += rinsum;

            gsum += ginsum;

            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;

            sir = stack[stackpointer];

            routsum += sir[0];

            goutsum += sir[1];

            boutsum += sir[2];

            rinsum -= sir[0];

            ginsum -= sir[1];

            binsum -= sir[2];

            yi += w;

        }

    }

    bitmap.setPixels(pix, 0, w, 0, 0, w, h);

    return (bitmap);

}