List of usage examples for java.awt.image ShortLookupTable ShortLookupTable
public ShortLookupTable(int offset, short[] data)
From source file:MainClass.java
public void paint(Graphics g) { short[] invert = new short[256]; for (int i = 0; i < invert.length; i++) invert[i] = (short) (255 - i); BufferedImageOp invertOp = new LookupOp(new ShortLookupTable(0, invert), null); BufferedImage clone = invertOp.filter(createImage(), null); g.drawImage(clone, 20, 20, this); }
From source file:Sampler.java
private void createLookups() { short[] brighten = new short[256]; short[] betterBrighten = new short[256]; short[] posterize = new short[256]; short[] invert = new short[256]; short[] straight = new short[256]; short[] zero = new short[256]; for (int i = 0; i < 256; i++) { brighten[i] = (short) (128 + i / 2); betterBrighten[i] = (short) (Math.sqrt((double) i / 255.0) * 255.0); posterize[i] = (short) (i - (i % 32)); invert[i] = (short) (255 - i); straight[i] = (short) i; zero[i] = (short) 0; }/*from w ww. j av a 2 s . c om*/ mOps.put("Brighten", new LookupOp(new ShortLookupTable(0, brighten), null)); mOps.put("Better Brighten", new LookupOp(new ShortLookupTable(0, betterBrighten), null)); mOps.put("Posterize", new LookupOp(new ShortLookupTable(0, posterize), null)); mOps.put("Invert", new LookupOp(new ShortLookupTable(0, invert), null)); short[][] redOnly = { invert, straight, straight }; short[][] greenOnly = { straight, invert, straight }; short[][] blueOnly = { straight, straight, invert }; mOps.put("Red invert", new LookupOp(new ShortLookupTable(0, redOnly), null)); mOps.put("Green invert", new LookupOp(new ShortLookupTable(0, greenOnly), null)); mOps.put("Blue invert", new LookupOp(new ShortLookupTable(0, blueOnly), null)); short[][] redRemove = { zero, straight, straight }; short[][] greenRemove = { straight, zero, straight }; short[][] blueRemove = { straight, straight, zero }; mOps.put("Red remove", new LookupOp(new ShortLookupTable(0, redRemove), null)); mOps.put("Green remove", new LookupOp(new ShortLookupTable(0, greenRemove), null)); mOps.put("Blue remove", new LookupOp(new ShortLookupTable(0, blueRemove), 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 a v a2 s.com }); 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:ColorApp.java
public void brightenLUT() { short brighten[] = new short[256]; for (int i = 0; i < 256; i++) { short pixelValue = (short) (i + 10); if (pixelValue > 255) pixelValue = 255;/*from w w w . j a va 2 s .c o m*/ else if (pixelValue < 0) pixelValue = 0; brighten[i] = pixelValue; } lookupTable = new ShortLookupTable(0, brighten); }
From source file:ColorApp.java
public void darkenLUT() { short brighten[] = new short[256]; for (int i = 0; i < 256; i++) { short pixelValue = (short) (i - 10); if (pixelValue > 255) pixelValue = 255;/*w ww .j av a 2 s .c o m*/ else if (pixelValue < 0) pixelValue = 0; brighten[i] = pixelValue; } lookupTable = new ShortLookupTable(0, brighten); }
From source file:ColorApp.java
public void contrastIncLUT() { short brighten[] = new short[256]; for (int i = 0; i < 256; i++) { short pixelValue = (short) (i * 1.2); if (pixelValue > 255) pixelValue = 255;/*from w w w . java 2 s .co m*/ else if (pixelValue < 0) pixelValue = 0; brighten[i] = pixelValue; } lookupTable = new ShortLookupTable(0, brighten); }
From source file:ColorApp.java
public void contrastDecLUT() { short brighten[] = new short[256]; for (int i = 0; i < 256; i++) { short pixelValue = (short) (i / 1.2); if (pixelValue > 255) pixelValue = 255;/*from w w w.j av a 2s.c o m*/ else if (pixelValue < 0) pixelValue = 0; brighten[i] = pixelValue; } lookupTable = new ShortLookupTable(0, brighten); }