Package java.awt.image

Examples of java.awt.image.ConvolveOp


    }
   
    private static void crashTest() {
        Raster src = createSrcRaster();
        WritableRaster dst = createDstRaster();
        ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP);
        try {
            op.filter(src, dst);
        } catch (ImagingOpException e) {
            /*
             * The test pair of source and destination rasters
             * may cause failure of the medialib convolution routine,
             * so this exception is expected.
View Full Code Here


        float[] kdata = new float[kw * kh];
        float v = 1f / kdata.length;
        Arrays.fill(kdata, v);
       
        Kernel k = new Kernel(kw, kh, kdata);
        ConvolveOp op = new ConvolveOp(k, edgeHint, null);
       
        return op;
    }
View Full Code Here

                areaSum += item;
                i++;
            }
            radiusX = i;
            dX = 0;
            conv[0] = new ConvolveOp(makeQualityKernelX());
        } else {
              //compute d
            dX = (int)Math.floor(DSQRT2PI*stdDeviationX+0.5f);
            int r = dX/2;
            if (dX%2 == 0)
                radiusX = 3*r-1; // even case
            else
                radiusX = 3*r;   // Odd case
        }
       
        if ((stdDeviationY < 2) ||
            hints.VALUE_RENDER_QUALITY.equals(hints.get(hints.KEY_RENDERING))){
              // compute the radiusY here
              // Start with 1/2 the zero box enery.
            areaSum = (float)(0.5/(stdDeviationY*SQRT2PI));
            int j=1;
            while (areaSum < precision){
                item =  (float)(Math.pow(Math.E, -j*j/
                                         (2*stdDeviationY*stdDeviationY)) /
                                (stdDeviationY*SQRT2PI));
                areaSum += item;
                j++;
            }
            radiusY = j;
            dY = 0;
            conv[1] = new ConvolveOp(makeQualityKernelY());
        } else {
              //compute d
            dY = (int)Math.floor(DSQRT2PI*stdDeviationY+0.5f);
            int r = dY/2;
            if (dY%2 == 0)
View Full Code Here

        float[] kernel = new float[blurMagnitude * blurMagnitude];
        for (int i = 0, n = kernel.length; i < n; i++) {
            kernel[i] = 1f / n;
        }

        ConvolveOp blur = new ConvolveOp(new Kernel(blurMagnitude, blurMagnitude,
            kernel), ConvolveOp.EDGE_NO_OP, null);
        bufferedImage = blur.filter(bufferedImage, null);

        this.graphics.drawImage(bufferedImage, 0, 0, null);
    }
View Full Code Here

        if (bias != 0.0)
            throw new IllegalArgumentException
                ("Only bias equal to zero is supported in ConvolveMatrix.");

        BufferedImageOp op = new ConvolveOp(kernel,
                                            ConvolveOp.EDGE_NO_OP,
                                            rh);

        ColorModel cm = cr.getColorModel();

        // OK this is a bit of a cheat. We Pull the DataBuffer out of
        // The read-only raster that getData gives us. And use it to
        // build a WritableRaster.  This avoids a copy of the data.
        Raster rr = cr.getData();
        WritableRaster wr = GraphicsUtil.makeRasterWritable(rr, 0, 0);

        // Here we update the translate to account for the phase shift
        // (if any) introduced by setting targetX, targetY in SVG.
        int phaseShiftX = target.x - kernel.getXOrigin();
        int phaseShiftY = target.y - kernel.getYOrigin();
        int destX = (int)(r.getX() + phaseShiftX);
        int destY = (int)(r.getY() + phaseShiftY);

        BufferedImage destBI;
        if (!preserveAlpha) {
            // Force the data to be premultiplied since often the JDK
            // code doesn't properly premultiply the values...
            cm = GraphicsUtil.coerceData(wr, cm, true);

            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Easy case just apply the op...
            destBI = op.filter(srcBI, null);

        } else {
            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Construct a linear sRGB cm without alpha...
            cm = new DirectColorModel(ColorSpace.getInstance
                                      (ColorSpace.CS_LINEAR_RGB), 24,
                                      0x00FF0000, 0x0000FF00,
                                      0x000000FF, 0x0, false,
                                      DataBuffer.TYPE_INT);



            // Create an image with that color model
            BufferedImage tmpSrcBI = new BufferedImage
                (cm, cm.createCompatibleWritableRaster(wr.getWidth(),
                                                       wr.getHeight()),
                 cm.isAlphaPremultiplied(), null);

            // Copy the color data (no alpha) to that image
            // (dividing out alpha if needed).
            GraphicsUtil.copyData(srcBI, tmpSrcBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpSrcBI: ", tmpSrcBI);

            // Get a linear sRGB Premult ColorModel
            ColorModel dstCM = GraphicsUtil.Linear_sRGB_Unpre;
            // Construct out output image around that ColorModel
            destBI = new BufferedImage
                (dstCM, dstCM.createCompatibleWritableRaster(wr.getWidth(),
                                                             wr.getHeight()),
                 dstCM.isAlphaPremultiplied(), null);

            // Construct another image on the same data buffer but without
            // an alpha channel.

            // Create the Raster (note we are using 'cm' again).
            WritableRaster dstWR =
                Raster.createWritableRaster
                (cm.createCompatibleSampleModel(wr.getWidth(), wr.getHeight()),
                 destBI.getRaster().getDataBuffer(),
                 new Point(0,0));

            // Create the BufferedImage.
            BufferedImage tmpDstBI = new BufferedImage
                (cm, dstWR, cm.isAlphaPremultiplied(), null);

            // Filter between the two image without alpha.
            tmpDstBI = op.filter(tmpSrcBI, tmpDstBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpDstBI: ", tmpDstBI);

            // Copy the alpha channel into the result (note the color
View Full Code Here

              0.111f, 0.111f, 0.111f,
              0.111f, 0.111f, 0.111f,
              0.111f, 0.111f, 0.111f,
          };

        BufferedImageOp op = new ConvolveOp( new Kernel(3, 3, matrix) );
        img = op.filter(img, new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB));
        return img;
  }
View Full Code Here

                      0.111f, 0.111f, 0.111f,
                      0.111f, 0.111f, 0.111f,
                      0.111f, 0.111f, 0.111f,
                  };

                BufferedImageOp op = new ConvolveOp( new Kernel(3, 3, matrix) );
                img = op.filter(img, new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB));
               
                int[] argb = img.getRGB(0, 0, 320, 240, null, 0, 320);
                if (mode.equals("calibrate")) {
                  String[] results = oculusImage.findBlobStart(x,y,img.getWidth(), img.getHeight(), argb);
                  autoDock("dockgrabbed calibrate "+results[0]+" "+results[1]+" "+results[2]+" "+results[3]+" "+results[4]+" "+
View Full Code Here

        if (horizontal) {
            kernel = new Kernel(size, 1, data);
        } else {
            kernel = new Kernel(1, size, data);
        }
        return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    }
View Full Code Here

        return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    }
   
    public static ConvolveOp[] getGaussianBlurFilter1DPair(int radius)
    {
        ConvolveOp op = getGaussianBlurFilter1D(radius, true);
       
        // Copy of data, but faster than recalculating
        float[] data = op.getKernel().getKernelData(null);
       
        ConvolveOp op1 = new ConvolveOp(new Kernel(1, op.getKernel().getWidth(), data),
                ConvolveOp.EDGE_NO_OP, null);
       
        return new ConvolveOp[] { op, op1 };
    }
View Full Code Here

        if (sharpenLevel == 1) {
            kernel = new Kernel(3, 3, new float[] { -0.25f, -0.5f, -0.25f, -0.5f, 4, -0.5f, -0.25f, -0.5f, -0.25f});
        } else {
            kernel = new Kernel(3, 3, new float[] { -0.5f, -1, -0.5f, -1, 7, -1, -0.5f, -1, -0.5f});
        }
        BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
        return op.filter(tmp, null);
    }
View Full Code Here

TOP

Related Classes of java.awt.image.ConvolveOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.