List of usage examples for java.awt.image.renderable ParameterBlock ParameterBlock
public ParameterBlock()
From source file:adams.data.imagemagick.PPMOutputConsumer.java
/** * Reads the ppm input stream into a {@link BufferedImage}. * /*from w w w.j a v a 2s. c om*/ * @param stream the stream to read from * @throws IOException if reading from stream fails */ @Override public void consumeOutput(InputStream stream) throws IOException { byte[] bytes; ByteArraySeekableStream bstream; ParameterBlock pb; RenderedOp op; m_Image = null; bytes = IOUtils.toByteArray(stream); bstream = new ByteArraySeekableStream(bytes); pb = new ParameterBlock(); pb.add(bstream); op = JAI.create("PNM", pb); m_Image = op.getAsBufferedImage(); }
From source file:omr.jai.RGBToBilevel.java
RGBToBilevel(final String fileName, boolean isErrorDiffusion) { // Load the file. PlanarImage src = JAI.create("fileload", fileName); // Load the ParameterBlock for the dithering operation // and set the operation name. ParameterBlock pb = new ParameterBlock(); pb.addSource(src);//from w ww . jav a 2 s .c o m String opName = null; if (isErrorDiffusion) { opName = "errordiffusion"; LookupTableJAI lut = new LookupTableJAI(new byte[][] { { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff } }); pb.add(lut); pb.add(KernelJAI.ERROR_FILTER_FLOYD_STEINBERG); } else { opName = "ordereddither"; ColorCube cube = ColorCube.createColorCube(DataBuffer.TYPE_BYTE, 0, new int[] { 2, 2, 2 }); pb.add(cube); pb.add(KernelJAI.DITHER_MASK_443); } // Create a layout containing an IndexColorModel which maps // zero to zero and unity to 255; force SampleModel to be bilevel. ImageLayout layout = new ImageLayout(); byte[] map = new byte[] { (byte) 0x00, (byte) 0xff }; ColorModel cm = new IndexColorModel(1, 2, map, map, map); layout.setColorModel(cm); SampleModel sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, src.getWidth(), src.getHeight(), 1); layout.setSampleModel(sm); // Create a hint containing the layout. RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); // Dither the image. final PlanarImage dst = JAI.create(opName, pb, hints); // Exit on window closing. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { JAI.create("filestore", dst, fileName + ".out", "PNG", null); System.exit(0); } }); // Display the result. //// ATTENTION A REMPLACER : add(new ScrollingImagePanel(dst, dst.getWidth(), dst.getHeight())); pack(); setVisible(true); }
From source file:imageLines.ImageHelpers.java
/**Perform a binary thresholding on the image using 1 of 5 methods 0-IterativeThreshold/* w ww .java 2 s . c o m*/ 1-MaxEntropyThreshold 2-Maximum Variance 3-Minimum Error 4-Minimum Fuzziness */ public static BufferedImage binaryThreshold(BufferedImage img, int method) { PlanarImage j = PlanarImage.wrapRenderedImage(img); //JAI.create("fileload", imageFile.getPath()); //double[][] matrix = {{ 0.114, 0.587, 0.299, 0 }}; double[][] matrix = { { 0.114, 0.587, 0.299, 0 } }; ParameterBlock pb = new ParameterBlock(); pb.addSource(j); pb.add(matrix); try { j = JAI.create("bandcombine", pb); } catch (IllegalArgumentException e) { } pb = new ParameterBlock(); pb.addSource(j); pb.add(null); // The ROI pb.add(1); pb.add(1); pb.add(new int[] { 256 }); pb.add(new double[] { 0 }); pb.add(new double[] { 256 }); // Calculate the histogram of the image. PlanarImage dummyImage = JAI.create("histogram", pb); Histogram h = (Histogram) dummyImage.getProperty("histogram"); // Calculate the thresholds based on the selected method. double[] thresholds = null; switch (method) { case 0: // Iterative Bisection thresholds = h.getIterativeThreshold(); break; case 1: // Maximum Entropy thresholds = h.getMaxEntropyThreshold(); break; case 2: // Maximum Variance thresholds = h.getMaxVarianceThreshold(); break; case 3: // Minimum Error thresholds = h.getMinErrorThreshold(); break; case 4: // Minimum Fuzziness thresholds = h.getMinFuzzinessThreshold(); break; } int threshold = (int) thresholds[0]; BufferedImage bin = (binarize(threshold, j)); return bin; }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doProgressiveBicubic(PlanarImage op) throws Exception { int dstWidth = 220; int w = op.getWidth(); while (w > dstWidth) { scale = 0.6f;/*from w w w.ja va 2s. c om*/ ParameterBlock pb = new ParameterBlock(); pb.addSource(op); pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); w = (int) (scale * w); } return op; }
From source file:omr.jai.TestImage3.java
public TestImage3() { JFrame frame = new JFrame(getClass().getName()); Container pane = frame.getContentPane(); pane.setLayout(new BorderLayout()); pane.add(this); image = decodeImage(new String[] { "#-###############", "-----------------", "#################", "-----------------", "#################", "-----------------", "#################", "-----------------", "#################", "-----------------", "#################", "-----------------", "-----------------", "-----------------", "---####----------", "-------##--------", "---------####----", "-------------#---", "-------------#---", "-----------------", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "--#############--", "-----------------", "-----------------", "---####----------", "-------##--------", "---------####----", "-------------#---", "-------------#---", "-----------------", "--#############--", "--#############--", "-----------------", "-----------------" });/* w w w . j a va2 s . co m*/ // checkImageFormat(); ImageInfo.print(image); // Scaling final float scale = 1f; ParameterBlock pb = new ParameterBlock() .addSource(image) .add(scale) .add(scale) .add(0f) .add(0f) .add(new InterpolationNearest()); image = JAI.create("scale", pb); dumpPixels(0, 0, 5, 7); if (false) { System.out.println("\nBand Selection"); image = JAI.create("bandselect",image,new int[] {0, 1, 2}); ImageInfo.print(image); dumpPixels(0, 0, 5, 7); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(100, 100); frame.pack(); frame.setSize(100, 250); frame.setVisible(true); }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleNearest(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);// w w w . j ava 2 s .c o m pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleBilinear(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);//www. ja va 2s . co m pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }
From source file:imageLines.ImageHelpers.java
/**Binarize a planar image. Only used internally.*/ private static BufferedImage binarize(int threshold, PlanarImage image) { // Binarizes the original image. if (threshold > 5) threshold -= 3;/*from w w w .j a va 2 s . c o m*/ ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(1.0 * threshold); // Creates a new, thresholded image and uses it on the DisplayJAI component PlanarImage thresholdedImage = JAI.create("binarize", pb); return thresholdedImage.getAsBufferedImage(); }
From source file:fr.gael.dhus.datastore.processing.impl.ProcessingUtils.java
public static RenderedImage ResizeImage(RenderedImage image, int width, int height, float max_ratio, boolean can_cut) { RenderedImage resizedImage = image; /*//from ww w . j a v a2 s .com // Select the displayable bands if (resizedImage.getNumBands () <= 2) { logger.debug("Grayscale image case"); resizedImage = JAI.create("bandselect", resizedImage, new int[] { 0 }); } else { logger.debug("RGB image case: [1 2 3]"); resizedImage = JAI.create("bandselect", resizedImage, new int[] {0, 1, 2}); } */ // Cut image if necessary if (can_cut == true) { resizedImage = ProcessingUtils.cutQuickLook(resizedImage, 2.0, 2); logger.debug("Image resized and cutted in band : " + resizedImage.getWidth() + "x" + resizedImage.getHeight()); } // Computes ratio and scale float scale = 1; if (resizedImage.getWidth() >= resizedImage.getHeight()) { scale = (float) ((double) width / (double) resizedImage.getWidth()); } else { scale = (float) ((double) height / (double) resizedImage.getHeight()); } // Processing resize process ParameterBlock pb = new ParameterBlock(); // The source image pb.addSource(resizedImage); // The xScale pb.add(scale); // The yScale pb.add(scale); // The x translation pb.add(0.0F); // The y translation pb.add(0.0F); // The interpolation pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC)); resizedImage = JAI.create("scale", pb, null); logger.debug("Image resized to : " + resizedImage.getWidth() + "x" + resizedImage.getHeight()); if ((width != resizedImage.getWidth()) && (height != resizedImage.getHeight())) { logger.debug("Final resize to complete expected image output"); resizedImage = ResizeImage(resizedImage, width, height, 0, false); } else { pb = new ParameterBlock().addSource(resizedImage); pb.add(new float[] { 0.002f }); // normalize factor 0.02% pb.add(null); // visible region pb.add(4); // x period pb.add(4); // y period resizedImage = JAI.create("normalize", pb); /* Does not work because of color model issue resizedImage = ColorQuantizerDescriptor.create( resizedImage, ColorQuantizerDescriptor.OCTTREE, new Integer(255), new Integer(300), null, new Integer(4), new Integer(4), null); */ } return resizedImage; }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleBicubic(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);//from w w w . j av a2s .c o m pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }