Example usage for java.awt.image LookupOp filter

List of usage examples for java.awt.image LookupOp filter

Introduction

In this page you can find the example usage for java.awt.image LookupOp filter.

Prototype

public final WritableRaster filter(Raster src, WritableRaster dst) 

Source Link

Document

Performs a lookup operation on a Raster .

Usage

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  . j  a  va2s  .  com
    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:ColorApp.java

public void applyFilter() {
    LookupOp lop = new LookupOp(lookupTable, null);
    lop.filter(bi, bi);
}

From source file:net.cloudkit.relaxation.VerifyImage.java

public void convBW(BufferedImage image) {
    byte[] threshold = new byte[256];

    for (int thresholdOp = 0; thresholdOp < 256; ++thresholdOp) {
        threshold[thresholdOp] = (byte) (thresholdOp < 128 ? 0 : -1);
    }/*from ww  w  .ja  v  a2 s  .c  om*/

    LookupOp var4 = new LookupOp(new ByteLookupTable(0, threshold), (RenderingHints) null);
    var4.filter(image, image);
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        BufferedImage image = convertImageType(ImgSource, BufferedImage.TYPE_INT_RGB);
        if (ImgSource != null) {
            try {
                LookupTable It = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_SFUNCION);
                LookupOp lop = new LookupOp(It, null);
                BufferedImage imgdest = lop.filter(image, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("Error");
            }/*w ww  .j  a v  a2s.c  om*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        BufferedImage image = convertImageType(ImgSource, BufferedImage.TYPE_INT_RGB);
        if (ImgSource != null) {
            try {
                LookupTable It = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_LOGARITHM);
                LookupOp lop = new LookupOp(It, null);
                BufferedImage imgdest = lop.filter(image, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("Error");
            }//from  w ww . jav  a 2s  .  c om
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        BufferedImage image = convertImageType(ImgSource, BufferedImage.TYPE_INT_RGB);
        if (ImgSource != null) {
            try {
                LookupTable It = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_POWER);
                LookupOp lop = new LookupOp(It, null);
                BufferedImage imgdest = lop.filter(image, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("Error");
            }/*from   w  w w  .  j  a v  a 2s  .  c  o  m*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void NegativoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NegativoActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) escritorio.getSelectedFrame();
    if (vi != null) {
        vi.getLienzo().getImage().getType();

        if (vi.getLienzo().getImage().getType() != BufferedImage.TYPE_INT_RGB) {
            BufferedImage img;//  w ww .  j a  v a2 s. c  o m
            img = new BufferedImage(vi.getLienzo().getImage().getWidth(), vi.getLienzo().getImage().getHeight(),
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = img.createGraphics();
            g2d.drawImage(vi.getLienzo().getImage(), 0, 0, null);
            vi.getLienzo().setImage(img);
        }

        if (vi.getLienzo().getImage() != null) {
            LookupTable lk = LookupTableProducer.createLookupTable(LookupTableProducer.TYPE_NEGATIVE);
            try {
                LookupOp l = new LookupOp(lk, null);
                BufferedImage imgdest = l.filter(vi.getLienzo().getImage(), null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println(e);
            }
        }

    }
}