List of usage examples for java.awt.image Kernel Kernel
public Kernel(int width, int height, float[] data)
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); Kernel kernel = new Kernel(3, 3, new float[] { -1, -1, -1, -1, 9, -1, -1, -1, -1 }); BufferedImageOp op = new ConvolveOp(kernel); bufferedImage = op.filter(bufferedImage, null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); Kernel kernel = new Kernel(3, 3, new float[] { 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f }); BufferedImageOp op = new ConvolveOp(kernel); bufferedImage = op.filter(bufferedImage, null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); Kernel kernel = new Kernel(3, 3, new float[] { -2, 0, 0, 0, 1, 0, 0, 0, 2 }); BufferedImageOp op = new ConvolveOp(kernel); bufferedImage = op.filter(bufferedImage, null); }
From source file:SaveIt.java
public static void main(String args[]) throws IOException { // Read/* ww w. j av a 2 s . 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:Main.java
private static ConvolveOp getLinearBlurOp(int size) { float[] data = new float[size * size]; float value = 1.0f / (float) (size * size); for (int i = 0; i < data.length; i++) { data[i] = value;//w ww . ja va 2s. c o m } return new ConvolveOp(new Kernel(size, size, data)); }
From source file:MainClass.java
public void paint(Graphics g) { BufferedImage img = createImage(); float ninth = 1.0f / 9.0f; float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth }; BufferedImageOp blurOp = new ConvolveOp(new Kernel(3, 3, blurKernel)); BufferedImage clone = blurOp.filter(img, null); g.drawImage(clone, 20, 20, this); }
From source file:BlurredImage.java
public void paint(Graphics g) { try {/*w w w .ja va 2s .com*/ BufferedImage myImage = ImageIO.read(this.getClass().getResource("redrock.png")); BufferedImage filteredImage = new BufferedImage(myImage.getWidth(null), myImage.getHeight(null), BufferedImage.TYPE_BYTE_GRAY); Graphics g1 = filteredImage.getGraphics(); g1.drawImage(myImage, 400, 200, null); float[] blurKernel = { 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f, 1 / 9f }; BufferedImageOp blur = new ConvolveOp(new Kernel(3, 3, blurKernel)); myImage = blur.filter(myImage, null); g1.dispose(); Graphics2D g2d = (Graphics2D) g; g2d.drawImage(myImage, null, 3, 3); } catch (Exception e) { } }
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:Main.java
/** * Applies a gaussian blur of the given radius to the given {@link BufferedImage} using a kernel * convolution./*w w w . j ava 2 s . c o m*/ * * @param source The source image. * @param radius The blur radius, in pixels. * @return A new, blurred image, or the source image if no blur is performed. */ public static BufferedImage blurredImage(BufferedImage source, double radius) { if (radius == 0) { return source; } final int r = (int) Math.ceil(radius); final int rows = r * 2 + 1; final float[] kernelData = new float[rows * rows]; final double sigma = radius / 3; final double sigma22 = 2 * sigma * sigma; final double sqrtPiSigma22 = Math.sqrt(Math.PI * sigma22); final double radius2 = radius * radius; double total = 0; int index = 0; double distance2; int x, y; for (y = -r; y <= r; y++) { for (x = -r; x <= r; x++) { distance2 = 1.0 * x * x + 1.0 * y * y; if (distance2 > radius2) { kernelData[index] = 0; } else { kernelData[index] = (float) (Math.exp(-distance2 / sigma22) / sqrtPiSigma22); } total += kernelData[index]; ++index; } } for (index = 0; index < kernelData.length; index++) { kernelData[index] /= total; } // We first pad the image so the kernel can operate at the edges. BufferedImage paddedSource = paddedImage(source, r); BufferedImage blurredPaddedImage = operatedImage(paddedSource, new ConvolveOp(new Kernel(rows, rows, kernelData), ConvolveOp.EDGE_ZERO_FILL, null)); return blurredPaddedImage.getSubimage(r, r, source.getWidth(), source.getHeight()); }
From source file:apiserver.services.images.services.jhlabs.BumpFilterService.java
public Object doFilter(Message<?> message) throws MessageConfigException { BumpJob props = (BumpJob) message.getPayload(); int edgeAction = props.getEdgeAction(); boolean useAlpha = props.isUseAlpha(); float[] embossMatrix = props.getMatrix(); try {/* www . j av a2 s. c o m*/ // calculate int rows = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue(); int cols = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue(); //run filter BumpFilter filter = new BumpFilter(); filter.setEdgeAction(edgeAction); filter.setUseAlpha(useAlpha); filter.setKernel(new Kernel(rows, cols, embossMatrix)); BufferedImage bufferedImage = props.getBufferedImage(); if (bufferedImage == null) { throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY); } BufferedImage outFile = filter.filter(bufferedImage, null); props.setBufferedImage(outFile); return message; } catch (Throwable e) { //log.error(e.getMessage(), e); throw new RuntimeException(e); } }