javax.media.jai.RenderedOp Java Examples

The following examples show how to use javax.media.jai.RenderedOp. 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: RdfThnCellRendererBig.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
    try {

        if (Thread.interrupted()) return;
        if (timeOut.get() > startTime) return;

        //ImageIcon icon = TiffConverter.getImageIcon(fileKey, 0, 0);
        RenderedImage img = imageProvider.getThumbnail(fileKey);
        img = contrastEnhancer.enhanceContrast(img);
        ImageIcon icon = new ImageIcon(RenderedOp.wrapRenderedImage(img).getAsBufferedImage());

        if ((iconHash != null) && (icon != null)) {
            iconHash.put(fileKey, icon);
            //setPreferredSize(new Dimension(getWidth(),icon.getImage().getHeight(list)));
            //list.revalidate();
            list.repaint();
        }
    } catch (Throwable t) {
        //can happen (e.g. outofmemory) but no problem
        //System.out.println("icon error: "+t);
        //t.printStackTrace();
    }
}
 
Example #2
Source File: OmsVectorizer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #3
Source File: MosaicPropertyGenerator.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public Object getProperty(final String name, final Object opNode) {
  validate(name, opNode);

  if ((opNode instanceof RenderedOp) && name.equalsIgnoreCase("sourceThreshold")) {
    final RenderedOp op = (RenderedOp) opNode;

    final ParameterBlock pb = op.getParameterBlock();

    // Retrieve the rendered source image and its ROI.
    final RenderedImage src = pb.getRenderedSource(0);
    final Object property = src.getProperty("sourceThreshold");
    if (property != null) {
      return property;
    } // Getting the Threshold to use
    final double threshold =
        CoverageUtilities.getMosaicThreshold(src.getSampleModel().getDataType());
    // Setting the Threshold object for the mosaic
    return new double[][] {{threshold}};
  }
  return java.awt.Image.UndefinedProperty;
}
 
Example #4
Source File: FolderImageStorage.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/** @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 #5
Source File: JAIConverter.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte[] terminateTiff(InputStream data) throws Exception {
	RenderedOp src = JAI.create("Stream", SeekableStream.wrapInputStream(data, true));
	PNGEncodeParam.Palette pngEncodeParam = new PNGEncodeParam.Palette();
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	ImageEncoder enc = ImageCodec.createImageEncoder("PNG", bos, pngEncodeParam);
	enc.encode(src);
	return bos.toByteArray();
}
 
Example #6
Source File: QuicklookSlstrDescriptor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create the Render Operator to compute SLSTR quicklook.
 *
 * <p>Creates a <code>ParameterBlockJAI</code> from all
 * supplied arguments except <code>hints</code> and invokes
 * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
 *
 * @see JAI
 * @see ParameterBlockJAI
 * @see RenderedOp
 *
 * @return The <code>RenderedOp</code> destination.
 * @throws IllegalArgumentException if sources is null.
 * @throws IllegalArgumentException if a source is null.
 */
public static RenderedOp create(PixelCorrection[]pixels_correction,
   RenderingHints hints, RenderedImage... sources)
{
   ParameterBlockJAI pb =
      new ParameterBlockJAI(OPERATION_NAME,
            RenderedRegistryMode.MODE_NAME);

   int numSources = sources.length;
   // Check on the source number
   if (numSources <= 0)
   {
      throw new IllegalArgumentException("No resources are present");
   }
   
   // Setting of all the sources
   for (int index = 0; index < numSources; index++)
   {
      RenderedImage source = sources[index];
      if (source == null)
      {
         throw new IllegalArgumentException("This resource is null");
      }
      pb.setSource(source, index);
      pb.setParameter(paramNames[0], pixels_correction);
   }
   return JAI.create(OPERATION_NAME, pb, hints);
}
 
Example #7
Source File: QuicklookOlciDescriptor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create the Render Operator to compute Olci quicklook.
 *
 * <p>Creates a <code>ParameterBlockJAI</code> from all
 * supplied arguments except <code>hints</code> and invokes
 * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
 *
 * @see JAI
 * @see ParameterBlockJAI
 * @see RenderedOp
 *
 * @param source_red the RenderedImage red source.
 * @param source_green the RenderedImage green source.
 * @param source_blue the RenderedImage blue source.
 * @param detectors list of detector indexes.
 * @param sza list of solar zenith angles.
 * @param solar_flux list of solar flux.
 * @param pixels_correction per bands scale/offset pixels correction
 * @param bands list of bands in the order they are provided.
 * @param bands_coefficients list of global coefficient per bands.
 * @return The <code>RenderedOp</code> destination.
 * @throws IllegalArgumentException if sources is null.
 * @throws IllegalArgumentException if a source is null.
 */
public static RenderedOp create(short[][] detectors, double[][]sza, 
   float[][]solar_flux, PixelCorrection[]pixels_correction, int[]bands,
   int[]bands_coefficients, RenderingHints hints, RenderedImage... sources)
{
   ParameterBlockJAI pb =
      new ParameterBlockJAI(OPERATION_NAME,
            RenderedRegistryMode.MODE_NAME);

   int numSources = sources.length;
   // Check on the source number
   if (numSources <= 0)
   {
      throw new IllegalArgumentException("No resources are present");
   }
   
   // Setting of all the sources
   for (int index = 0; index < numSources; index++)
   {
      RenderedImage source = sources[index];
      if (source == null)
      {
         throw new IllegalArgumentException("This resource is null");
      }
      pb.setSource(source, index);
   }
   /*To Be remove */
   pb.setParameter(paramNames[0], detectors);
   pb.setParameter(paramNames[1], sza);
   pb.setParameter(paramNames[2], solar_flux);
   pb.setParameter(paramNames[3], pixels_correction);
   pb.setParameter(paramNames[4], bands);
   pb.setParameter(paramNames[5], bands_coefficients);
   
   return JAI.create(OPERATION_NAME, pb, hints);
}
 
Example #8
Source File: S3HistogramEqualizerDescriptor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Render the Equalization of pixels of the image.
 *
 * <p>Creates a <code>ParameterBlockJAI</code> from all
 * supplied arguments except <code>hints</code> and invokes
 * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
 *
 * @see JAI
 * @see ParameterBlockJAI
 * @see RenderedOp
 *
 * @param hints processing image hints.
 * @param sources list of sources.
 * @return The <code>RenderedOp</code> destination.
 * @throws IllegalArgumentException if <code>sources</code> is <code>null</code>.
 * @throws IllegalArgumentException if a <code>source</code> is <code>null</code>.
 */
public static RenderedOp create(RenderingHints hints, RenderedImage... sources)
{
   ParameterBlockJAI pb =
      new ParameterBlockJAI(OPERATION_NAME,
            RenderedRegistryMode.MODE_NAME);

   int numSources = sources.length;
   // Check on the source number
   if (numSources <= 0)
   {
      throw new IllegalArgumentException("No resources are present");
   }
   
   // Setting of all the sources
   for (int index = 0; index < numSources; index++)
   {
      RenderedImage source = sources[index];
      if (source == null)
      {
         throw new IllegalArgumentException("This resource is null");
      }
      pb.setSource(source, index);
   }
   
   return JAI.create(OPERATION_NAME, pb, hints);
}
 
Example #9
Source File: ImageUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private BufferedImage privateReadFromFile(final File file, final boolean forOpenGL) throws IOException {
	// DEBUG.OUT("READING " + file.getName());
	BufferedImage result = getNoImage();
	if (file == null) { return result; }
	final String name = file.getName();
	String ext = null;
	if (name.contains(".")) {
		ext = name.substring(file.getName().lastIndexOf('.'));
	}
	if (tiffExt.contains(ext)) {
		try (FileSeekableStream stream = new FileSeekableStream(file.getAbsolutePath())) {
			/**
			 * AD TODO : decodeParam is not used ...
			 */
			// final TIFFDecodeParam decodeParam = new TIFFDecodeParam();
			// decodeParam.setDecodePaletteAsShorts(true);
			final ParameterBlock params = new ParameterBlock();
			params.add(stream);
			final RenderedOp image1 = JAI.create("tiff", params);
			return image1.getAsBufferedImage();
		}
	} else if (gifExt.contains(ext)) {
		final GifDecoder d = new GifDecoder();
		d.read(new FileInputStream(file.getAbsolutePath()));
		return d.getImage();
	}

	try {
		result = forOpenGL ? ImageIO.read(file) : toCompatibleImage(ImageIO.read(file));
	} catch (final Exception e) {
		return getNoImage();
	}
	return result;
}
 
Example #10
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper function to run the Vectorize operation with given parameters and
 * retrieve the vectors.
 * 
 * @param src the source {@link GridCoverage2D}.
 * @param args a {@code Map} of parameter names and values or <code>null</code>.
 * 
 * @return the generated vectors as JTS Polygons
 */
@SuppressWarnings("unchecked")
public static Collection<Polygon> doVectorize( GridCoverage2D src, Map<String, Object> args ) {
    if (args == null) {
        args = new HashMap<String, Object>();
    }

    ParameterBlockJAI pb = new ParameterBlockJAI("Vectorize");
    pb.setSource("source0", src.getRenderedImage());

    // 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
    Collection<Polygon> polygons = (Collection<Polygon>) dest.getProperty(VectorizeDescriptor.VECTOR_PROPERTY_NAME);

    RegionMap regionParams = CoverageUtilities.getRegionParamsFromGridCoverage(src);
    double xRes = regionParams.getXres();
    double yRes = regionParams.getYres();
    final AffineTransform mt2D = (AffineTransform) src.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER);
    final AffineTransformation jtsTransformation = new AffineTransformation(mt2D.getScaleX(), mt2D.getShearX(),
            mt2D.getTranslateX() - xRes / 2.0, mt2D.getShearY(), mt2D.getScaleY(), mt2D.getTranslateY() + yRes / 2.0);
    for( Polygon polygon : polygons ) {
        polygon.apply(jtsTransformation);
    }
    return polygons;
}
 
Example #11
Source File: WebPWriterTest.java    From webp-imageio with Apache License 2.0 5 votes vote down vote up
/**
 * Test method tests {@link WebPWriter} with image resize options.
 *
 * @throws IOException
 *            the test fails.
 */
@Test(dataProvider = "createImagesWithScaleOptions", enabled = true)
public void testImageWriterScale(final RenderedImage image, final float xScale,
      final float yScale, final String outputName) throws IOException {
   final String extension = outputName.substring(outputName.lastIndexOf(".") + 1);

   // Scale the image.
   final RenderedOp scaledImage = ScaleDescriptor.create(image, xScale, yScale, 0f, 0f,
         Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2), null);

   // get writer
   final ImageWriter imgWriter = ImageIO.getImageWritersByFormatName(extension).next();
   final ImageWriteParam imgWriteParams = new WebPWriteParam(null);
   final String testName = "ScaleOptions";
   final File file = createOutputFile(testName, outputName);
   final ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(file);
   try {
      imgWriter.setOutput(imageOutputStream);
      imgWriter.write(null, new IIOImage(scaledImage, null, null), imgWriteParams);
      final int length = (int) imageOutputStream.length();
      assertTrue(length > 0);
   } finally {
      try {
         imageOutputStream.close();
      } catch (final IOException e) {
      }
   }
}
 
Example #12
Source File: ImageStorageTest.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** 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 #13
Source File: Sentinel2Image.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
public static RenderedImage process1BImage (DrbCollectionImage source, 
   int bands, int horizontal_padding, int vertical_padding)
{
   // Prepare output mosaic layout
   ImageLayout layout = new ImageLayout();
   boolean isLayoutTileSet = false;

   // Prepare variables for building output strip mosaic
   int currentWidth = horizontal_padding;
   int currentHeight = vertical_padding;
   
   ParameterBlockJAI mosaicParameters = 
      new ParameterBlockJAI("Mosaic", "rendered");
   
   mosaicParameters.setParameter("mosaicType",
      javax.media.jai.operator.MosaicDescriptor.MOSAIC_TYPE_BLEND);
   
   Collection<DrbImage>images = source.getChildren();
   Iterator<DrbImage> image_it = images.iterator();
   while (image_it.hasNext())
   {
      RenderedImage current_image = null;

      // Select the working bands
      ParameterBlock pb = new ParameterBlock();
      DrbImage fmt = null;
      if (bands>1)
      {
         for (int i=0; i<bands; i++)
         {
            fmt = image_it.next();
            ParameterBlock fmt_pb = new ParameterBlock();
            fmt_pb.addSource(fmt);
            fmt_pb.add(DataBuffer.TYPE_BYTE);
            RenderedOp op = JAI.create("Format", fmt_pb);
         
            pb.addSource(op);
         }
         current_image = JAI.create("bandMerge", pb);
      }
      else
      {
         //Probably PVI image
         current_image = image_it.next();
      }
      
      // Set layout tile size if not already done
      if (!isLayoutTileSet)
      {
         layout.setTileWidth(current_image.getTileWidth());
         layout.setTileHeight(current_image.getTileHeight());
         layout.setColorModel(current_image.getColorModel());
         layout.setSampleModel(current_image.getSampleModel());

         isLayoutTileSet = true;
      }

      // Translate strip to the output coordinate (vertical shift)
      ParameterBlock translateParameters = new ParameterBlock();

      translateParameters.addSource(current_image);
      translateParameters.add((float) currentWidth);
      translateParameters.add((float) currentHeight);
      translateParameters.add(new InterpolationNearest());

      current_image = JAI.create("translate", translateParameters,
         new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));

      // TODO: find a way to retrieves the granules position within
      // the mosaic. 
      // Update following strip translation
      /*
      if ((source_index%13)==0)
      {*/
         currentWidth=horizontal_padding;
         currentHeight += current_image.getHeight() + vertical_padding;
         /*
      }
      else
      {
         currentWidth += current_image.getWidth() + horizontal_padding;
      }*/

      // Add current strip to the output mosaic
      mosaicParameters.addSource(current_image);
      // Go to the next image
   }
   double [] backgroundValues = new double [bands];
   for (int j = 0; j < bands; j++) {
       backgroundValues[j] = 0.0D;
   }        
   mosaicParameters.setParameter("backgroundValues", backgroundValues);
   // Create output mosaic
   return JAI.create("mosaic", mosaicParameters,
      new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
}
 
Example #14
Source File: MosaicPropertyGenerator.java    From geowave with Apache License 2.0 4 votes vote down vote up
public MosaicPropertyGenerator() {
  super(
      new String[] {"sourceThreshold"},
      new Class[] {double[][].class},
      new Class[] {RenderedOp.class});
}
 
Example #15
Source File: ImageStorage.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
public void storeImage(RenderedOp img,
String id) throws ImageStorageException;
 
Example #16
Source File: ImageStorage.java    From pdfxtk with Apache License 2.0 votes vote down vote up
public RenderedOp getImage(String id) throws ImageStorageException;