List of usage examples for java.awt.image RescaleOp RescaleOp
public RescaleOp(float scaleFactor, float offset, RenderingHints hints)
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); float scaleFactor = 1.3f; RescaleOp op = new RescaleOp(scaleFactor, 0, null); bufferedImage = op.filter(bufferedImage, null); }
From source file:Main.java
/** * Inverts the alpha channel of the given {@link BufferedImage}. RGB data for the inverted area * are undefined, so it's generally best to fill the resulting image with a color. * * @param source The source image./*w w w .j a v a 2 s.c o m*/ * @return A new image with an alpha channel inverted from the original. */ public static BufferedImage invertedAlphaImage(BufferedImage source) { final float[] scaleFactors = new float[] { 1, 1, 1, -1 }; final float[] offsets = new float[] { 0, 0, 0, 255 }; return operatedImage(source, new RescaleOp(scaleFactors, offsets, null)); }
From source file:ImageProcessingTest.java
public ImageProcessingFrame() { setTitle("ImageProcessingTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); add(new JComponent() { public void paintComponent(Graphics g) { if (image != null) g.drawImage(image, 0, 0, null); }//w w w .j ava 2 s.c o m }); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile(); } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenu editMenu = new JMenu("Edit"); JMenuItem blurItem = new JMenuItem("Blur"); blurItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float weight = 1.0f / 9.0f; float[] elements = new float[9]; for (int i = 0; i < 9; i++) elements[i] = weight; convolve(elements); } }); editMenu.add(blurItem); JMenuItem sharpenItem = new JMenuItem("Sharpen"); sharpenItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f }; convolve(elements); } }); editMenu.add(sharpenItem); JMenuItem brightenItem = new JMenuItem("Brighten"); brightenItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float a = 1.1f; // float b = 20.0f; float b = 0; RescaleOp op = new RescaleOp(a, b, null); filter(op); } }); editMenu.add(brightenItem); JMenuItem edgeDetectItem = new JMenuItem("Edge detect"); edgeDetectItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { float[] elements = { 0.0f, -1.0f, 0.0f, -1.0f, 4.f, -1.0f, 0.0f, -1.0f, 0.0f }; convolve(elements); } }); editMenu.add(edgeDetectItem); JMenuItem negativeItem = new JMenuItem("Negative"); negativeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { short[] negative = new short[256 * 1]; for (int i = 0; i < 256; i++) negative[i] = (short) (255 - i); ShortLookupTable table = new ShortLookupTable(0, negative); LookupOp op = new LookupOp(table, null); filter(op); } }); editMenu.add(negativeItem); JMenuItem rotateItem = new JMenuItem("Rotate"); rotateItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (image == null) return; AffineTransform transform = AffineTransform.getRotateInstance(Math.toRadians(5), image.getWidth() / 2, image.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC); filter(op); } }); editMenu.add(rotateItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); menuBar.add(editMenu); setJMenuBar(menuBar); }
From source file:TRescaleOp.java
public void rescale() { rescale = new RescaleOp(scaleFactor, offset, null); rescale.filter(biSrc, biDest); 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 . j a v a 2 s .co 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:ImageDrawingComponent.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; switch (opIndex) { case 0: /* copy */ g.drawImage(bi, 0, 0, null);/*from w ww . j a v a2 s . co m*/ break; case 1: /* scale up using coordinates */ g.drawImage(bi, 0, 0, w, h, /* dst rectangle */ 0, 0, w / 2, h / 2, /* src area of image */ null); break; case 2: /* scale down using transform */ g2.drawImage(bi, AffineTransform.getScaleInstance(0.7, 0.7), null); break; case 3: /* scale up using transform Op and BICUBIC interpolation */ AffineTransform at = AffineTransform.getScaleInstance(1.5, 1.5); AffineTransformOp aop = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC); g2.drawImage(bi, aop, 0, 0); break; case 4: /* low pass filter */ case 5: /* sharpen */ float[] data = (opIndex == 4) ? BLUR3x3 : SHARPEN3x3; ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null); g2.drawImage(bi, cop, 0, 0); break; case 6: /* rescale */ RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); g2.drawImage(bi, rop, 0, 0); break; case 7: /* lookup */ byte lut[] = new byte[256]; for (int j = 0; j < 256; j++) { lut[j] = (byte) (256 - j); } ByteLookupTable blut = new ByteLookupTable(0, lut); LookupOp lop = new LookupOp(blut, null); g2.drawImage(bi, lop, 0, 0); break; default: } }
From source file:Sampler.java
private void createRescales() { mOps.put("Rescale .5, 0", new RescaleOp(.5f, 0, null)); mOps.put("Rescale .5, 64", new RescaleOp(.5f, 64, null)); mOps.put("Rescale 1.2, 0", new RescaleOp(1.2f, 0, null)); mOps.put("Rescale 1.5, 0", new RescaleOp(1.5f, 0, null)); }
From source file:org.iish.visualmets.services.ImageTransformation.java
public BufferedImage ContrastBrightnessImage(BufferedImage img, float contrast, float brightness) { // BRIGHTNESS / CONTRAST // scale factor (contrast) (bv. 0 - zwart, 1 - default, 5 - heel licht) // offset (brightness) (bv. -100, -90, ..., -20, -10, 0, 10, 20, 90, 100) if (contrast != 1f || brightness != 0f) { RescaleOp rescaleOp = new RescaleOp(contrast, brightness, null); rescaleOp.filter(img, img);/*from w ww .ja v a2 s.co m*/ } return img; }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static void drawImageWithAlpha(Graphics2D g, BufferedImage img, int alpha) { float[] edgeScales = { 1f, 1f, 1f, alpha / 255.0f }; float[] edgeOffsets = new float[4]; g.drawImage(img, new RescaleOp(edgeScales, edgeOffsets, null), 0, 0); }
From source file:org.apache.cocoon.reading.ImageReader.java
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { char lastChar; String tmpWidth = par.getParameter("width", "0"); String tmpHeight = par.getParameter("height", "0"); this.scaleColor[0] = par.getParameterAsFloat("scaleRed", -1.0f); this.scaleColor[1] = par.getParameterAsFloat("scaleGreen", -1.0f); this.scaleColor[2] = par.getParameterAsFloat("scaleBlue", -1.0f); this.offsetColor[0] = par.getParameterAsFloat("offsetRed", 0.0f); this.offsetColor[1] = par.getParameterAsFloat("offsetGreen", 0.0f); this.offsetColor[2] = par.getParameterAsFloat("offsetBlue", 0.0f); this.quality[0] = par.getParameterAsFloat("quality", 0.9f); boolean filterColor = false; for (int i = 0; i < 3; ++i) { if (this.scaleColor[i] != -1.0f) { filterColor = true;/* w ww. j a v a2 s .c o m*/ } else { this.scaleColor[i] = 1.0f; } if (this.offsetColor[i] != 0.0f) { filterColor = true; } } if (filterColor) { this.colorFilter = new RescaleOp(scaleColor, offsetColor, null); } usePercent = false; lastChar = tmpWidth.charAt(tmpWidth.length() - 1); if (lastChar == '%') { usePercent = true; width = Integer.parseInt(tmpWidth.substring(0, tmpWidth.length() - 1)); } else { width = Integer.parseInt(tmpWidth); } lastChar = tmpHeight.charAt(tmpHeight.length() - 1); if (lastChar == '%') { usePercent = true; height = Integer.parseInt(tmpHeight.substring(0, tmpHeight.length() - 1)); } else { height = Integer.parseInt(tmpHeight); } if (par.getParameterAsBoolean("grayscale", GRAYSCALE_DEFAULT)) { this.grayscaleFilter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); } this.enlarge = par.getParameterAsBoolean("allow-enlarging", ENLARGE_DEFAULT); this.fitUniform = par.getParameterAsBoolean("fit-uniform", FIT_DEFAULT); super.setup(resolver, objectModel, src, par); }