List of usage examples for java.awt.image Kernel Kernel
public Kernel(int width, int height, float[] data)
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:com.esri.ArcGISController.java
@PostConstruct public void postConstruct() throws IOException { m_patternEqual = Pattern.compile("="); m_patternComma = Pattern.compile(","); m_patternSemiColon = Pattern.compile(";"); final 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 }); m_op = new ConvolveOp(kernel); final Resource resource = m_resourceLoader.getResource("classpath:/InfoUSA.json"); final InputStream inputStream = resource.getInputStream(); if (inputStream != null) { try {/*from w w w .j a v a2 s . c o m*/ IOUtils.copy(inputStream, m_byteArrayOutputStream); } finally { inputStream.close(); } } m_xofs = WebMercator.longitudeToX(m_xofs); m_yofs = WebMercator.latitudeToY(m_yofs); }
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 w ww. ja va 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 v a 2s . c o m 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 . jav a2 s . com 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);// w w w . j a v a2 s . 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: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 a 2 s.c o m*/ bi = biDest; }
From source file:ConvolveApp.java
public void edgeDetect() { float data[] = { 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f }; 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 a 2 s . c o m*/ bi = biDest; }