Example usage for java.awt.image ConvolveOp EDGE_NO_OP

List of usage examples for java.awt.image ConvolveOp EDGE_NO_OP

Introduction

In this page you can find the example usage for java.awt.image ConvolveOp EDGE_NO_OP.

Prototype

int EDGE_NO_OP

To view the source code for java.awt.image ConvolveOp EDGE_NO_OP.

Click Source Link

Document

Pixels at the edge of the source image are copied to the corresponding pixels in the destination without modification.

Usage

From source file:SaveIt.java

public static void main(String args[]) throws IOException {
    // Read/*from  w ww  . j a va  2s .com*/
    File inputFile = new File("java2s.jpg");
    BufferedImage input = ImageIO.read(inputFile);
    // Convert
    Kernel kernel = new Kernel(3, 3, SHARP);
    ConvolveOp convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    int width = input.getWidth();
    int height = input.getHeight();
    BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    convolveOp.filter(input, output);
    // Save
    File outputFile = new File("java2s.png");
    ImageIO.write(output, "PNG", outputFile);
}

From source file:ConvolveIt.java

public ConvolveIt() {
    int width = image.getWidth(this);
    int height = image.getHeight(this);
    bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bufferedImage.createGraphics();
    AffineTransform affineTransform = new AffineTransform();
    big.drawImage(image, affineTransform, this);
    Kernel kernel = new Kernel(3, 3, SHARP);
    convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
}

From source file:Sampler.java

private void createConvolutions() {
    float ninth = 1.0f / 9.0f;
    float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth };
    mOps.put("Blur", new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, null));

    float[] edge = { 0f, -1f, 0f, -1f, 4f, -1f, 0f, -1f, 0f };
    mOps.put("Edge detector", new ConvolveOp(new Kernel(3, 3, edge), ConvolveOp.EDGE_NO_OP, null));

    float[] sharp = { 0f, -1f, 0f, -1f, 5f, -1f, 0f, -1f, 0f };
    mOps.put("Sharpen", new ConvolveOp(new Kernel(3, 3, sharp)));
}

From source file:editeurpanovisu.ReadWriteImage.java

public static void writeTiff(Image imgImage, String strNomFich, boolean bSharpen, float sharpenLevel)
        throws ImageReadException, IOException {
    File file = new File(strNomFich);
    BufferedImage imageRGBSharpen = null;
    BufferedImage imageRGB = SwingFXUtils.fromFXImage(imgImage, null);

    Graphics2D graphics = imageRGB.createGraphics();
    graphics.drawImage(imageRGB, 0, 0, null);
    if (bSharpen) {
        imageRGBSharpen = new BufferedImage(imageRGB.getWidth(), imageRGB.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        Kernel kernel = new Kernel(3, 3, sharpenMatrix);
        ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
        cop.filter(imageRGB, imageRGBSharpen);
    }//from www .j  a v  a 2  s. c om

    final ImageFormat format = ImageFormats.TIFF;
    final Map<String, Object> params = new HashMap<>();
    params.put(ImagingConstants.PARAM_KEY_COMPRESSION,
            new Integer(TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));

    if (bSharpen) {
        try {
            Imaging.writeImage(imageRGBSharpen, file, format, params);
        } catch (ImageWriteException ex) {
            Logger.getLogger(ReadWriteImage.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        try {
            Imaging.writeImage(imageRGB, file, format, params);
        } catch (ImageWriteException ex) {
            Logger.getLogger(ReadWriteImage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:Myopia.java

public BlurLayerUI() {
    float ninth = 1.0f / 9.0f;
    float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth };
    mOperation = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, null);
}

From source file:Java2DExample.java

public BufferedImage processImage(BufferedImage image) {
    float[] blurMatrix = { 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f,
            1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f };
    BufferedImageOp blurFilter = new ConvolveOp(new Kernel(3, 3, blurMatrix), ConvolveOp.EDGE_NO_OP, null);
    return blurFilter.filter(image, null);
}

From source file:SaveImage.java

public void filterImage() {
    BufferedImageOp op = null;/*from w w  w. j  a va  2 s.  c  om*/

    if (opIndex == lastOp) {
        return;
    }
    lastOp = opIndex;
    switch (opIndex) {

    case 0:
        biFiltered = bi; /* original */
        return;
    case 1: /* low pass filter */
    case 2: /* sharpen */
        float[] data = (opIndex == 1) ? BLUR3x3 : SHARPEN3x3;
        op = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null);

        break;

    case 3: /* lookup */
        byte lut[] = new byte[256];
        for (int j = 0; j < 256; j++) {
            lut[j] = (byte) (256 - j);
        }
        ByteLookupTable blut = new ByteLookupTable(0, lut);
        op = new LookupOp(blut, null);
        break;
    }

    /*
     * Rather than directly drawing the filtered image to the destination,
     * filter it into a new image first, then that filtered image is ready for
     * writing out or painting.
     */
    biFiltered = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    op.filter(bi, biFiltered);
}

From source file:ConvolveApp.java

public void sharpen() {
    float data[] = { -1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f, -1.0f };
    Kernel kernel = new Kernel(3, 3, data);
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    convolve.filter(biSrc, biDest);// w ww  .  j  a  v  a  2s .  c  o m
    bi = biDest;
}

From source file:ImageOps.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    int w = getSize().width;
    int h = getSize().height;

    g2.setColor(Color.black);/*from   w w  w  .ja  v  a 2s. c  o m*/
    float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter
            0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 };

    String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" };
    for (int i = 0; i < bi.length; i++) {
        int iw = bi[i].getWidth(this);
        int ih = bi[i].getHeight(this);
        int x = 0, y = 0;

        AffineTransform at = new AffineTransform();
        at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih);

        BufferedImageOp biop = null;
        BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);

        switch (i) {
        case 0:
        case 1:
            x = i == 0 ? 5 : w / 2 + 3;
            y = 15;
            Kernel kernel = new Kernel(3, 3, data[i]);
            ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
            cop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            break;
        case 2:
            x = 5;
            y = h / 2 + 15;
            byte chlut[] = new byte[256];
            for (int j = 0; j < 200; j++)
                chlut[j] = (byte) (256 - j);
            ByteLookupTable blut = new ByteLookupTable(0, chlut);
            LookupOp lop = new LookupOp(blut, null);
            lop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            break;
        case 3:
            x = w / 2 + 3;
            y = h / 2 + 15;
            RescaleOp rop = new RescaleOp(1.1f, 20.0f, null);
            rop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
        }
        g2.drawImage(bimg, biop, x, y);
        TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, (float) x, (float) y - 4);
    }
}

From source file:ConvolveApp.java

public void blur() {
    float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f };
    Kernel kernel = new Kernel(3, 3, data);
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    convolve.filter(biSrc, biDest);/*from w  w w.j  a  v a2s .  co  m*/
    bi = biDest;
}