javax.media.jai.JAI Java Examples
The following examples show how to use
javax.media.jai.JAI.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OmsVectorizer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Helper function to run the Vectorize operation with given parameters and * retrieve the vectors. * * @param src the source image * @param args a {@code Map} of parameter names and values * * @return the generated vectors as JTS Polygons */ @SuppressWarnings("unchecked") private Collection<Polygon> doVectorize( RenderedImage src, Map<String, Object> args ) { ParameterBlockJAI pb = new ParameterBlockJAI("Vectorize"); pb.setSource("source0", src); // Set any parameters that were passed in for( Entry<String, Object> e : args.entrySet() ) { pb.setParameter(e.getKey(), e.getValue()); } // Get the desintation image: this is the unmodified source image data // plus a property for the generated vectors RenderedOp dest = JAI.create("Vectorize", pb); // Get the vectors Object property = dest.getProperty(VectorizeDescriptor.VECTOR_PROPERTY_NAME); return (Collection<Polygon>) property; }
Example #2
Source File: FolderImageStorage.java From pdfxtk with Apache License 2.0 | 6 votes |
/** @param id unique id given to the image */ public RenderedOp getImage(String id) throws ImageStorageException { try { File f = new File(folder+"sign_"+id+".tif"); FileInputStream is = new FileInputStream(f); byte[] b = new byte[(new Long(f.length())).intValue()]; is.read(b); ByteArraySeekableStream stream = new ByteArraySeekableStream(b); RenderedOp img = JAI.create("stream",stream); is.close(); return img; } catch(FileNotFoundException e1) { throw new ImageStorageException ("File "+folder+"sign_"+id+".tif not found"); } catch(IOException e2) { throw new ImageStorageException ("Class FolderImageStorage : IOException throwed : msg : "+e2.getMessage()); } }
Example #3
Source File: JaiLoader.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Try to load an image, using JAI. * This seems limited to a single image, thus no id parameter is to be * provided. * * @param imgFile the input file * @return a map of one image, or null if failed to load */ public static SortedMap<Integer, BufferedImage> loadJAI (File imgFile) { BufferedImage image = JAI.create("fileload", imgFile.getPath()).getAsBufferedImage(); try { if ((image.getWidth() > 0) && (image.getHeight() > 0)) { SortedMap<Integer, BufferedImage> images = new TreeMap<>(); images.put(1, image); return images; } } catch (Exception ex) { logger.debug(ex.getMessage()); } return null; }
Example #4
Source File: ImageLoading.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Try to use JAI. * * @param imgPath the provided input file * @return proper (JAI) loader or null if failed */ private static Loader getJaiLoader (Path imgPath) { logger.debug("getJaiLoader {}", imgPath); try { BufferedImage image = JAI.create("fileload", imgPath.toString()).getAsBufferedImage(); if ((image != null) && (image.getWidth() > 0) && (image.getHeight() > 0)) { return new JaiLoader(image); } logger.debug("No image read by JAI for {}", imgPath); } catch (Exception ex) { logger.warn("JAI failed opening {}, {} ", imgPath, ex.toString(), ex); } return null; }
Example #5
Source File: JaiLoader.java From libreveris with GNU Lesser General Public License v3.0 | 6 votes |
/** * Try to load an image, using JAI. * This seems limited to a single image, thus no id parameter is to be * provided. * * @param imgFile the input file * @return a map of one image, or null if failed to load */ public static SortedMap<Integer, RenderedImage> loadJAI (File imgFile) { RenderedImage image = JAI.create("fileload", imgFile.getPath()); try { if ((image.getWidth() > 0) && (image.getHeight() > 0)) { SortedMap<Integer, RenderedImage> images = new TreeMap<>(); images.put(1, image); return images; } } catch (Exception ex) { logger.debug(ex.getMessage()); } return null; }
Example #6
Source File: HilightImagePanel.java From pdfxtk with Apache License 2.0 | 6 votes |
/** Test program */ public static void main(String[] arg) { PlanarImage image = JAI.create("fileload", arg[0]); PlanarImage mask = JAI.create("fileload", arg[1]); JFrame window = new JFrame(); window.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); window.getContentPane().add(new HilightImagePanel(image, mask, Color.blue), BorderLayout.CENTER); window.pack(); window.setSize(300, 300); window.setLocation(40, 40); window.show(); }
Example #7
Source File: PerformancePanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private String getTileDimensionValuesForBenchmark(String tileDimension) { StringBuilder defaultTileSizeValues = new StringBuilder(); defaultTileSizeValues.append("128"); defaultTileSizeValues.append(BENCHMARK_SEPARATOR); defaultTileSizeValues.append("256"); defaultTileSizeValues.append(BENCHMARK_SEPARATOR); defaultTileSizeValues.append("512"); defaultTileSizeValues.append(BENCHMARK_SEPARATOR); defaultTileSizeValues.append("*"); defaultTileSizeValues.append(BENCHMARK_SEPARATOR); //return defaultTileSizeValues.toString(); return JAI.getDefaultTileSize().width + "," + JAI.getDefaultTileSize().height; }
Example #8
Source File: WarpRIF.java From geowave with Apache License 2.0 | 5 votes |
public static synchronized void register(final boolean force) { if (!registered || force) { final OperationRegistry registry = JAI.getDefaultInstance().getOperationRegistry(); final RenderedImageFactory rif = new WarpRIF(); registry.registerFactory( RenderedRegistryMode.MODE_NAME, "Warp", "it.geosolutions.jaiext", rif); registered = true; } }
Example #9
Source File: TestImage3.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static PlanarImage grayToGray256 (PlanarImage image) { System.out.println("Converting gray image to gray-256 ..."); ColorSpace colorSpace = ColorSpace.getInstance (java.awt.color.ColorSpace.CS_GRAY); // int[] bits = new int[]{8}; // int opaque = Transparency.OPAQUE; // int dataType = DataBuffer.TYPE_BYTE; // ColorModel colorModel = new ComponentColorModel // (colorSpace, bits, false, false, opaque, dataType); return JAI.create("colorConvert", image, colorSpace, null); }
Example #10
Source File: TestImage3.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static PlanarImage colorToGray (PlanarImage image) { System.out.println("Converting color image to gray ..."); double[][] matrix = { {0.114d, 0.587d, 0.299d, 0.0d} }; return JAI.create("bandcombine", new ParameterBlock() .addSource(image) .add(matrix), null); }
Example #11
Source File: TestImage3.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static PlanarImage invert (PlanarImage image) { return JAI.create("Invert", new ParameterBlock() .addSource(image) .add(null) .add(null) .add(null) .add(null) .add(null), null); }
Example #12
Source File: TestWarp.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static RenderedImage invert (RenderedImage image) { return JAI.create( "Invert", new ParameterBlock().addSource(image).add(null).add(null).add(null).add( null).add(null), null); }
Example #13
Source File: TestWarp.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a new TestWarp object. */ public TestWarp (String path) { srcImage = JAI.create("fileload", new ParameterBlock().add(path), null); // srcImage = PictureLoader.loadImages(new File(path), null) // .get(1); // srcImage = buildPattern(20, 10, 50, 50); dimension = new Dimension(srcImage.getWidth(), srcImage.getHeight()); setPreferredSize(dimension); // float[] xCoeffs = new float[] { 0f, 1.25f, 0.04f }; // float[] yCoeffs = new float[] { 0f, -0.02f, 1.5f }; // Warp warp = new WarpAffine(xCoeffs, yCoeffs); // int xStep = 500; int xNumCells = 2; int yStep = 500; int yNumCells = 1; float[] warpPositions = new float[] { -100f, 0f, 500f, 100f, 1000f, 0f, // top line 0f, 500f, 500f, 500f, 1000f, 500f }; // bot line Warp warp = new WarpGrid( 0, xStep, xNumCells, 0, yStep, yNumCells, warpPositions); ParameterBlock pb = new ParameterBlock(); pb.addSource(invert(srcImage)); pb.add(warp); pb.add(new InterpolationBilinear()); dstImage = invert(JAI.create("warp", pb)); ((PlanarImage) dstImage).getTiles(); }
Example #14
Source File: JaiDewarper.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
public RenderedImage dewarpImage () { ParameterBlock pb = new ParameterBlock(); pb.addSource(Picture.invert(sheet.getPicture().getImage())); pb.add(dewarpGrid); pb.add(new InterpolationBilinear()); RenderedImage dewarpedImage = Picture.invert(JAI.create("warp", pb)); ((PlanarImage) dewarpedImage).getTiles(); return dewarpedImage; }
Example #15
Source File: Picture.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * Check if the image format (and especially its color model) is * properly handled by Audiveris. * * @throws ImageFormatException is the format is not supported */ private void checkImageFormat () throws ImageFormatException { ColorModel colorModel = image.getColorModel(); int pixelSize = colorModel.getPixelSize(); boolean hasAlpha = colorModel.hasAlpha(); logger.debug("{}", colorModel); if (pixelSize == 1) { ///image = binaryToGray(image); // Only if rotation is needed! implicitForeground = 0; } // Check nb of bands SampleModel sampleModel = image.getSampleModel(); int numBands = sampleModel.getNumBands(); logger.debug("numBands={}", numBands); if (numBands == 1) { // Pixel gray value. Nothing to do } else if ((numBands == 2) && hasAlpha) { // Pixel + alpha // Discard alpha (TODO: check if premultiplied!!!) image = JAI.create("bandselect", image, new int[]{}); } else if ((numBands == 3) && !hasAlpha) { // RGB image = RGBToGray(image); } else if ((numBands == 4) && hasAlpha) { // RGB + alpha image = RGBAToGray(image); } else { throw new ImageFormatException( "Unsupported sample model numBands=" + numBands); } }
Example #16
Source File: Picture.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
private static PlanarImage RGBAToGray (PlanarImage image) { logger.info("Discarding alpha band ..."); PlanarImage pi = JAI.create("bandselect", image, new int[]{0, 1, 2}); return RGBToGray(pi); }
Example #17
Source File: ImageUtil.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Take an RGB image and combine the R,G and B bands according to standard luminance * value to provide the output gray value. * * @param rgb input image with 3 bands RGB * @return a gray image */ public static BufferedImage rgbToGray (BufferedImage rgb) { logger.info("Converting RGB to gray ..."); // We use luminance value based on standard RGB combination double[][] matrix = {{0.114d, 0.587d, 0.299d, 0.0d}}; return JAI.create("bandcombine", new ParameterBlock().addSource(rgb).add(matrix), null) .getAsBufferedImage(); }
Example #18
Source File: PerformancePanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void processingParamsComputeButtonActionPerformed(java.awt.event.ActionEvent evt) { if(validCompute()){ //Create performance parameters benchmark lists java.util.List<Integer> tileSizeList = new ArrayList<>(); java.util.List<String> tileDimensionList = new ArrayList<>(); java.util.List<Integer> cacheSizesList = new ArrayList<>(); java.util.List<Integer> nbThreadsList = new ArrayList<>(); for(String tileSize : StringUtils.split(benchmarkTileSizeTextField.getText(), ';')){ tileSizeList.add(Integer.parseInt(tileSize)); } //for(String dimension : StringUtils.split(benchmarkTileSizeTextField.getText(), ';')){ // tileDimensionList.add(dimension); //} tileDimensionList.add(JAI.getDefaultTileSize().width + "," + JAI.getDefaultTileSize().height); for(String cacheSize : StringUtils.split(cacheSizeTextField.getText(), ';')){ cacheSizesList.add(Integer.parseInt(cacheSize)); } for(String nbThread : StringUtils.split(benchmarkNbThreadsTextField.getText(), ';')){ nbThreadsList.add(Integer.parseInt(nbThread)); } Benchmark benchmarkModel = new Benchmark(tileSizeList, tileDimensionList, cacheSizesList, nbThreadsList); String opName = procGraphJComboBox.getSelectedItem().toString(); AppContext appContext = SnapApp.getDefault().getAppContext(); //launch Benchmark dialog BenchmarkDialog productDialog = new BenchmarkDialog(this, opName, benchmarkModel, appContext); productDialog.show(); } }
Example #19
Source File: SourceThresholdFixMosaicDescriptor.java From geowave with Apache License 2.0 | 5 votes |
public static synchronized void register(final boolean force) { if (!registered || force) { final OperationRegistry registry = JAI.getDefaultInstance().getOperationRegistry(); registry.unregisterDescriptor(new MosaicDescriptor()); registry.registerDescriptor(new SourceThresholdFixMosaicDescriptor()); // there seems to be a bug in jai-ext, line 1211 of // concurrentoperationregistry null pointer exception registry.registerFactory("rendered", "Mosaic", "com.sun.media.jai", new MosaicRIF()); registered = true; } }
Example #20
Source File: Picture.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Check if the image format (and especially its color model) is * properly handled by Audiveris and adjust if needed. * * @throws ImageFormatException is the format is not supported */ private BufferedImage adjustImageFormat (BufferedImage img) throws ImageFormatException { ColorModel colorModel = img.getColorModel(); boolean hasAlpha = colorModel.hasAlpha(); logger.debug("{}", colorModel); // Check nb of bands SampleModel sampleModel = img.getSampleModel(); int numBands = sampleModel.getNumBands(); logger.debug("numBands={}", numBands); if (numBands == 1) { // Pixel gray value. Nothing to do return img; } else if ((numBands == 2) && hasAlpha) { // Pixel + alpha // Discard alpha return JAI.create("bandselect", img, new int[]{0}).getAsBufferedImage(); } else if ((numBands == 3) && !hasAlpha) { // RGB return ImageUtil.maxRgbToGray(img); } else if ((numBands == 4) && hasAlpha) { // RGB + alpha return ImageUtil.maxRgbaToGray(img); } else { throw new ImageFormatException( "Unsupported sample model numBands=" + numBands + " hasAlpha=" + hasAlpha); } }
Example #21
Source File: SkeletonDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); SkeletonDescriptor desc = new SkeletonDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "skeleton", "iiuf.jai", desc); }
Example #22
Source File: BlackOrDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); BlackOrDescriptor desc = new BlackOrDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "blackor", "iiuf.jai", desc); }
Example #23
Source File: PowerDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); PowerDescriptor desc = new PowerDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "power", "iiuf.jai", desc); }
Example #24
Source File: BinarizeDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); BinarizeDescriptor desc = new BinarizeDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "binarize", "iiuf.jai", desc); }
Example #25
Source File: ImageViewer.java From pdfxtk with Apache License 2.0 | 5 votes |
public static void main(String[] arg) { if (arg.length != 1) { System.err.println("Usage: iiuf.jai.ImageViewer <image>"); System.exit(0); } new ImageViewer(JAI.create("fileload", arg[0])); }
Example #26
Source File: CCDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); CCDescriptor desc = new CCDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "cc", "iiuf.jai", desc); }
Example #27
Source File: RLSADescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); RLSADescriptor desc = new RLSADescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "rlsa", "iiuf.jai", desc); }
Example #28
Source File: ImageStorageTest.java From pdfxtk with Apache License 2.0 | 5 votes |
/** construct an ImageStorage based on a folder @param folder name of the folder used to put and get images */ public ImageStorageTest(String imgName, String folderName) throws ImageStorageException { ImageStorage imgStore = new FolderImageStorage(folderName); RenderedOp img = JAI.create("fileload",imgName); imgStore.storeImage(img,"toto.tif+100+100+100+100"); img = imgStore.getImage("toto.tif+100+100+100+100"); imgStore.storeImage(img,"tutu.tif+10+10+50+50"); }
Example #29
Source File: ProjectionProfileDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
public static void register() { if (!registered) { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); ProjectionProfileDescriptor desc = new ProjectionProfileDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "projectionprofile", "iiuf.jai", desc); registered = true; } }
Example #30
Source File: RandomizeDescriptor.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Registers this operator with the JAI environment */ public static void register() { OperationRegistry or = JAI.getDefaultInstance().getOperationRegistry(); RandomizeDescriptor desc = new RandomizeDescriptor(); or.registerDescriptor(desc); RIFRegistry.register(or, "randomize", "iiuf.jai", desc); }