List of usage examples for java.awt.image ConvolveOp ConvolveOp
public ConvolveOp(Kernel kernel)
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: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
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;// ww w .ja v a 2 s . co 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 {// ww w .j a v a 2 s . c om 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: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 ww .j a v a 2s . c om*/ IOUtils.copy(inputStream, m_byteArrayOutputStream); } finally { inputStream.close(); } } m_xofs = WebMercator.longitudeToX(m_xofs); m_yofs = WebMercator.latitudeToY(m_yofs); }
From source file:edu.emory.library.tast.images.ThumbnailServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // location of images String baseUrl = AppConfig.getConfiguration().getString(AppConfig.IMAGES_URL); baseUrl = StringUtils.trimEnd(baseUrl, '/'); // image name and size String imageFileName = request.getParameter("i"); int thumbnailWidth = Integer.parseInt(request.getParameter("w")); int thumbnailHeight = Integer.parseInt(request.getParameter("h")); // image dir// w w w . j ava2 s .c o m String imagesDir = AppConfig.getConfiguration().getString(AppConfig.IMAGES_DIRECTORY); // create the thumbnail name String thumbnailFileName = FilenameUtils.getBaseName(imageFileName) + "-" + thumbnailWidth + "x" + thumbnailHeight + ".png"; // does it exist? File thumbnailFile = new File(imagesDir, thumbnailFileName); if (thumbnailFile.exists()) { response.sendRedirect(baseUrl + "/" + thumbnailFileName); return; } // read the image File imageFile = new File(imagesDir, imageFileName); BufferedImage image = ImageIO.read(imageFile); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); BufferedImage imageCopy = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); imageCopy.getGraphics().drawImage(image, 0, 0, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight, null); // height is calculated automatically if (thumbnailHeight == 0) thumbnailHeight = (int) ((double) thumbnailWidth / (double) imageWidth * (double) imageHeight); // width is calculated automatically if (thumbnailWidth == 0) thumbnailWidth = (int) ((double) thumbnailHeight / (double) imageHeight * (double) imageWidth); // create an empty thumbnail BufferedImage thumbnail = new BufferedImage(thumbnailWidth, thumbnailHeight, BufferedImage.TYPE_INT_RGB); Graphics2D gr = thumbnail.createGraphics(); gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // determine the piece of the image which we want to clip int clipX1, clipX2, clipY1, clipY2; if (imageWidth * thumbnailHeight > thumbnailWidth * imageHeight) { int clipWidth = (int) Math .round(((double) thumbnailWidth / (double) thumbnailHeight) * (double) imageHeight); int imgCenterX = imageWidth / 2; clipX1 = imgCenterX - clipWidth / 2; clipX2 = imgCenterX + clipWidth / 2; clipY1 = 0; clipY2 = imageHeight; } else { int clipHeight = (int) Math .round(((double) thumbnailHeight / (double) thumbnailWidth) * (double) imageWidth); int imgCenterY = imageHeight / 2; clipX1 = 0; clipX2 = imageWidth; clipY1 = imgCenterY - clipHeight / 2; clipY2 = imgCenterY + clipHeight / 2; } // we filter the image first to get better results when shrinking if (2 * thumbnailWidth < clipX2 - clipX1 || 2 * thumbnailHeight < clipY2 - clipY1) { int kernelDimX = (clipX2 - clipX1) / (thumbnailWidth); int kernelDimY = (clipY2 - clipY1) / (thumbnailHeight); if (kernelDimX % 2 == 0) kernelDimX++; if (kernelDimY % 2 == 0) kernelDimY++; if (kernelDimX < kernelDimY) kernelDimX = kernelDimY; if (kernelDimY < kernelDimX) kernelDimY = kernelDimX; float[] blurKernel = new float[kernelDimX * kernelDimY]; for (int i = 0; i < kernelDimX; i++) for (int j = 0; j < kernelDimY; j++) blurKernel[i * kernelDimX + j] = 1.0f / (float) (kernelDimX * kernelDimY); BufferedImageOp op = new ConvolveOp(new Kernel(kernelDimX, kernelDimY, blurKernel)); imageCopy = op.filter(imageCopy, null); } // draw the thumbnail gr.drawImage(imageCopy, 0, 0, thumbnailWidth, thumbnailHeight, clipX1, clipY1, clipX2, clipY2, null); // and we are done gr.dispose(); ImageIO.write(thumbnail, "png", thumbnailFile); // redirect to it response.sendRedirect(baseUrl + "/" + thumbnailFileName); }
From source file:ImageProcessingTest.java
/** * Apply a convolution and repaint.//from w w w . j a v a2 s . com * @param elements the convolution kernel (an array of 9 matrix elements) */ private void convolve(float[] elements) { Kernel kernel = new Kernel(3, 3, elements); ConvolveOp op = new ConvolveOp(kernel); filter(op); }
From source file:distribuidos.MyThread.java
private void difuminarTrozo(int x, int y, int w, int h) { preSC();/* w ww . ja va2 s .c om*/ BufferedImage original = null; BufferedImage nueva = null; try { original = ImageIO.read(new File(imagepath)); nueva = ImageIO.read(new File(newimagepath)); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } BufferedImage copia = new BufferedImage(original.getWidth(), original.getHeight(), TYPE_BYTE_INDEXED); float[] floats = { 0, 0.125f, 0, 0.125f, 0.5f, 0.125f, 0, 0.125f, 0, }; BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, floats)); op.filter(original, copia); copia = copia.getSubimage(x, y, w, h); Graphics2D g2d = nueva.createGraphics(); g2d.drawImage(copia, x, y, null); //g2d.drawImage(copia, x, y, w, h, null); File output = new File(newimagepath); try { ImageIO.write(nueva, "png", output); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } postSC(); }