[kepler-dev] JAI actors

Christopher Brooks cxh at eecs.berkeley.edu
Thu Dec 1 14:23:07 PST 2005


Hi Nandita,
Thanks for taking a look.

There are two forces at work here:

1) Duplicate code is bad.

I'd hate to see the same actors in both places.

The ptolemy.actor.lib.jai code was written by James Yeh, a student who
has since finished his Masters.  The code could use a sponsor, and I
have no problem having anyone make changes in it.

2) Kepler needs to get credit for Kepler work.  This points towards
not doing the work in the Ptolemy tree and instead working on these
actors in the kepler tree.

I'd prefer choice #1, where we avoid duplicate code and you work in
the ptolemy.actor.lib.jai tree.  I can easily give you write access
to the Ptolemy devel tree.  I do ask that you stick with the Ptolemy
style.

However, since Ptolemy does not have the Kepler documentation system,
this would mean the ptolemy.actor.lib.jai actors would not have Kepler
style documentation.  Once hack would be to extend the ptolemy actors
in Kepler and document them there, but that seems very poor.

So, the choice is yours.  I won't be offended if you stick developing
these in the Kepler tree,  but I wanted to make sure that we were
making a conscious decision.  Comparing and contrasting the designs
probably helped you with some design decisions.

BTW - we have a proposal out that includes hacking on the Ptolemy
documentation system.  In the proposal we mentioned the Kepler system,
so there is a possibility of modifying Ptolemy so that it is more
compatible with the Kepler doc system.  I'm not sure if we will get
the proposal, but there is interest in this sort of work.

_Christopher

--------

    Hello Chirstopher,
    I spent a little bit time looking over the Ptolemy and Kepler actors. The
    following are some of the distinctions/similarities.
    Please feel free to correct me/other suggestions.
    thanks,
    Nandita.
    
    ------------------------------------------------------------------
    JAI Ptolemy & Kepler Evaluations
    11/30/05
    
    Unique Ptolemy JAI Actors:
    
    AdaptiveMedian: An actor that performs adaptive median filtering on a
    double matrix.
    DoubleMatrixtoJai: Converts a matrix of doubles into a single-banded
    JAIImageToken.
    ImageToken to JAI: Convert an ImageToken to a JAIImageToken.
    JAIBandCombine: An actor that combines input bands for an output image.
    JAIBandSelect: An actor that copies bands from an image into another.
    JAIBMPWriter: An actor that writes to a bitmap file.
    JAIBorder: An actor that adds a border to an image.
    JAIBoxFilter: An actor that box filters an image.
    JAIConstant: An actor that produces a JAIImageToken with constant bands.
    JAIDataConvert: An actor that changes the data format in a JAIImageToken.
    JAICDT: Calculates the discrete cosine transform of a RenderedOp.
    JAIFDT: Calculates the discrete Fourier transform of a RenderedOp.
    JAIImageReader: An actor that produces a JAIImageToken from an image file
    specified
     as a URL.
    JAIImageToken: A token that contains a javax.media.jai.RenderedOp.
    JAIJPEGWriter: An actor that writes to a JPEG file.
    JAIPNGWriter: An actor that writes to a PNG file.
    JAIPNMWriter: An actor that writes to a PNM file.
    JAITiffWriter: An actor that writes to a TIFF file.
    JAILog: An actor that outputs the logarithm of an image.
    JAIMagnitude: An actor that outputs the magnitude of a complex image.
    JAIMedianFilter: An actor that median filters an image.
    JAIPeriodicShift: An actor that box periodically shifts an image.
    JAIPhase: An actor that outputs the phase of a complex image.
    JAIPolarToComplex: An actor that outputs the a complex image from a
    magnitude and
     phase input.
    JAIToDoubleMatrix: Takes a JAIImageToken, and outputs the data as a
    DoubleMatrixToken.
    JAITranspose: An actor that transposes image
    SaltPepper: Randomly change values in a double matrix to 0.0 or 255.0.
    
    
    Similar Ptolemy and Kepler Actors
    
    (Ptolemy) AffineTransformation
    Requires an affineTranformation matrix as a parameter.
    Based on interpolating type (specified as a String attribute), render an
    input image with the specified affine matrix and output the new image.
    (Kepler) Affine Tranformations
    No affine matrix, however the user is asked for X, Y co-ordinates of
    translation/shearing.
    AffineTranformations such as scaling, simply take in a scale value.
    Input values such as X, Y co-ordinates or values such as scale are
    available as port parameters for automated execution in workflows.
    
    (Ptolemy)ImageCrop
    Takes in X,Y origins as well as width, height as input parameters. Crops
    an image.
    (Kepler) ImageCrop
    Adds X,Y origins as port parameters for automated execution in workflows.
    Crops an image. All other functionality same.
    
    (Ptolemy)ImageInvert & (Kepler) ImageInvert
     No difference
    
    (Ptolemy)JAIRotate:
    Rotates around a point
    (Kepler)ImageRotate
    Rotates by angle.
    
    (Ptolemy)ImageScale
    Scaling based on parameters such as width, height of expected image.
    XScaleFactor, YScaleFactor as well as interpolation type being used for
    the above transformation.
    (Kepler)ImageScale
    Scaling based on only one parameter of scale extent desired (specified as
    a port parameter for automated execution in workflows). Ptolemy actor
    gives much more other scaling options compared to Kepler Image Scaler.
    
    (Ptolemy)ImageTranslate & (Kepler)ImageTranslate
    No difference except Kepler takes in port parameters for x,y translation
    values for automated execution in workflows
    
    (Ptolemy)JAIConvolve
    An actor that convolves an input image based on a filter(specified as a
    parameter double matrix)
    (Kepler)Convolve Operations
    Performs convolve operations based on extent/level desired input from user
    as a port parameters. (Sharpen/Blur/EdgeDetect)
    
    Unique Kepler actors:
    
    ImageViewerJAI: An actor which display normal images as well as JAI
    images, in a viewer.
    ImageCompositor: Composites two images
    ImageContourPlotter: Given a matrix of data as input, plots a contour plot
    ImageAddText: Adds textual information to an image at various
    alignments/fonts.
    
    End Note:
    Ptolemy provides a huge range of possible image manipulations, by using
    basic JAI operator wrappers provided by the JAI API.
    
    However, most of the actors do not add the flexibility of putting such
    actors in automated execution workflows with least level of
    user-interactivity. Kepler Imaging actors keeping that flexibility in mind
    have added PortParameters as inputs for image manipulations in various
    actors. One can modify existing Ptolemy actors to add this flexibility or
    make use of Kepler Actors depending on further discussion results.
    On the other hand, some Unique Ptolemy actors can prove useful in future
    scientific workflows. Image Scaler for example of Ptolemy gives a user
    more options to modify the image as compared to ImageScaler of Kepler.
    
    Another feature distinct in Ptolemy actors, is that they are dependent on
    specifying a double matrix for affine/filter operations. Kepler Actors
    provide the user with the basic operations in affine /filter operations.
    However improvement can be made by modifying either Kepler/Ptolemy actors
    to incorporate both features of either using a commonly used operation or
    custom operation in the same actor.
    
    
    ---------------------------------------------------------------------
    
    
    
    > Hi Nandita,
    >
    > How are these classes different from the JAI classes in
    > ptolemy/actor/lib/jai?
    >
    > AdaptiveMedian.java       JAIDFT.java               JAIPNMWriter.java
    > DoubleMatrixToJAI.java    JAIDataConvert.java       JAIPeriodicShift.java
    > ImageToJAI.java           JAIEdgeDetection.java     JAIPhase.java
    > JAIAffineTransform.java   JAIIDCT.java              JAIPolarToComplex.jav
   a
    > JAIBMPWriter.java         JAIIDFT.java              JAIRotate.java
    > JAIBandCombine.java       JAIImageReader.java       JAIScale.java
    > JAIBandSelect.java        JAIImageToken.java        JAITIFFWriter.java
    > JAIBorder.java            JAIInvert.java            JAIToDoubleMatrix.jav
   a
    > JAIBoxFilter.java         JAIJPEGWriter.java        JAITranslate.java
    > JAIConstant.java          JAILog.java               JAITranspose.java
    > JAIConvolve.java          JAIMagnitude.java         JAIWriter.java
    > JAICrop.java              JAIMedianFilter.java      SaltAndPepper.java
    > JAIDCT.java               JAIPNGWriter.java
    >
    > For example, there is JAITranslate.java in ptolemy/actor/lib/jai
    > and it looks like you are creating a similar actor?
    >
    > If you would like, I could give you write access to the Ptolemy tree
    > and you could work there.
    > If you really need your own version of these actors, then perhaps the
    > class comment should state why the versions in ptolemy/actor/lib/jai
    > are not sufficient.
    >
    > _Christopher
    >
    > --------
    >
    >     mangal      05/11/25 14:11:58
    >
    >       Added:       src/util ImageTranslate.java
    >       Log:
    >       Image Affine Transformation actor for translation
    >
    >       Revision  Changes    Path
    >       1.1                  kepler/src/util/ImageTranslate.java
    >
    >       Index: ImageTranslate.java
    >       ===================================================================
    >        /** Image Translate is an image manipulation actor for translating
    >        * based on the specified information.
    >        *
    >        * Copyright (c) 2004 The Regents of the University of California.
    >        * All rights reserved.
    >        *
    >        * Permission is hereby granted, without written agreement and
    > without
    >        * license or royalty fees, to use, copy, modify, and distribute
    > this
    >        * software and its documentation for any purpose, provided that th
   e
    >        * above copyright notice and the following two paragraphs appear i
   n
    >        * all copies of this software.
    >        *
    >        * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
    > PARTY
    >        * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    > DAMAGES
    >        * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
    > EVEN
    >        * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
    > POSSIBILITY
    >        * OF SUCH DAMAGE.
    >        *
    >        * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
    > WARRANTIES,
    >        * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    >        * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
    > SOFTWARE
    >        * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
    >        * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
    >        * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    >        */
    >
    >       package util;
    >
    >
    >       import ptolemy.actor.TypedAtomicActor;
    >       import ptolemy.actor.TypedIOPort;
    >       import ptolemy.data.StringToken;
    >       import ptolemy.kernel.CompositeEntity;
    >       import ptolemy.kernel.util.*;
    >       import ptolemy.data.type.BaseType;
    >       import ptolemy.data.ObjectToken;
    >       import ptolemy.data.AWTImageToken;
    >       import ptolemy.data.expr.Parameter;
    >       import ptolemy.data.expr.StringParameter;
    >       import ptolemy.actor.parameters.PortParameter;
    >       import ptolemy.data.*;
    >
    >       import java.awt.*;
    >       import java.awt.image.*;
    >       import java.net.*;
    >       import javax.imageio.*;
    >       import javax.swing.*;
    >       import java.io.*;
    >       import java.util.*;
    >       import java.lang.Float;
    >
    >       //For JAI usage
    >       import javax.media.jai.JAI;
    >       import javax.media.jai.*;
    >       import javax.media.jai.PlanarImage;
    >       import java.awt.image.renderable.ParameterBlock;
    >       import javax.media.jai.KernelJAI;
    >       import javax.media.jai.InterpolationBicubic;
    >       import javax.media.jai.InterpolationBicubic2;
    >
    >
    >       /**
    >        * ImageTranslate can be used to translate at the given
    >        * X,Y translation co-ordinates.
    >        @author Nandita Mangal
    >        @version $Id: ImageTranslate.java,v 1.1 2005/11/02 00:21:52
    >        @category.name Image Manipulation
    >        */
    >
    >       public class ImageTranslate extends TypedAtomicActor
    >       {
    >
    >           ///////////////////////////////////////////////////////////////
   //////
    >    //
    >           ////                   Parameters and Ports
    >  ///
    >    /
    >
    >
    >           /*
    >            * The input image to be translated
    >            */
    >           public TypedIOPort imgSrc;
    >
    >           /*
    >            * The output manipulated image
    >            */
    >           public TypedIOPort imgDest;
    >
    >           /*
    >            * The translating coordinate X
    >            */
    >           public PortParameter x_translation ;
    >
    >           /*
    >            * The translating coordinate y
    >            */
    >           public PortParameter y_translation ;
    >
    >           /*
    >            * The type of interpolation for the
    >            * above transformation.
    >            */
    >            public StringParameter interpolationType ;
    >
    >
    >
    >         /**
    >          * constructor for ImageCrop with the given container and name.
    >          *
    >          *@param  container                     The container.
    >           *@param  name                          The name of this actor.
    >          *@exception  IllegalActionException    If the actor cannot be
    > containe
    >    d
    >          *   by the proposed container.
    >          *@exception  NameDuplicationException  If the container already
    > has an
    >          *   actor with this name.
    >          */
    >         public ImageTranslate(CompositeEntity container, String name)
    >           throws
    >             NameDuplicationException, IllegalActionException
    >         {
    >           super(container, name);
    >
    >                imgSrc = new TypedIOPort(this, "Source Image", true,
    > false);
    >       	 imgSrc.setTypeEquals(BaseType.OBJECT);
    >                imgSrc.setMultiport(false);
    >
    >                imgDest = new TypedIOPort(this, "Dest Image", false, true)
   ;
    >       	 imgDest.setTypeEquals(BaseType.OBJECT);
    >                imgDest.setMultiport(false);
    >
    >                x_translation  = new PortParameter(this,"X Translation");
    >                x_translation.setExpression("50");
    >
    >                y_translation  = new PortParameter(this,"Y Translation");
    >                y_translation.setExpression("100");
    >
    >                interpolationType = new
    > StringParameter(this,"InterpolationType"
    >    );
    >                interpolationType.setExpression("INTERPOLATION_NEAREST");
    >       	 interpolationType.addChoice("INTERPOLATION_BILINEAR");
    >       	 interpolationType.addChoice("INTERPOLATION_BICUBIC");
    >                interpolationType.addChoice("INTERPOLATION_BICUBIC2");
    >
    >
    >         }
    >           ///////////////////////////////////////////////////////////////
   //////
    >    ///
    >           ////                 public methods
    >   //
    >    //
    >
    >
    >         /**
    >          * The source image is retrieved from the input port of the actor
    >          * and a JAI PlanarImage is created from the input image.
    >          * After calculating, the cropped image's specifications such
    >          * as width,height,Co-ordinates the image is cropped with the
    > JAI.creat
    >    e
    >          * operator.
    >          *@exception  IllegalActionException  If there is no director.
    >          */
    >         public void fire()
    >           throws IllegalActionException
    >         {
    >           super.fire();
    >           PlanarImage input=null;
    >           Object inputToken = imgSrc.get(0);
    >
    >           if(inputToken instanceof AWTImageToken)
    >           {
    >           	Image src = (Image)((AWTImageToken)inputToken).getValue
   ();
    >           	input= JAI.create("awtimage",src);
    >           }
    >           else if (inputToken instanceof ObjectToken)
    >           {
    >       	input =(PlanarImage)((ObjectToken)inputToken).getValue();
    >
    >           }
    >
    >
    >           x_translation.update();
    >           y_translation.update();
    >
    >           Token t_x = x_translation.getToken();
    >           Token t_y = y_translation.getToken();
    >           String x_str="";
    >           String y_str="";
    >
    >           if(t_x instanceof IntToken)
    >                 x_str= new String ( ((IntToken)t_x).intValue() + "");
    >           else if(t_x instanceof DoubleToken)
    >       	    x_str= new String ( ((DoubleToken)t_x).intValue() + "");
    >
    >           if(t_y instanceof IntToken)
    >                y_str= new String ( ((IntToken)t_y).intValue() + "");
    >           else if (t_y instanceof DoubleToken)
    >       	   y_str= new String ( ((DoubleToken)t_y).intValue() + "");
    >
    >
    >           float x_trans =Float.parseFloat(x_str);
    >           float y_trans =Float.parseFloat(y_str);
    >
    >           String interpolation = interpolationType.stringValue();
    >
    >           Interpolation interp=null;
    >
    >           if(interpolation.equals("INTERPOLATION_NEAREST"))
    >       	    interp = new InterpolationNearest();
    >           else if(interpolation.equals("INTERPOLATION_BILINEAR"))
    >       	    interp = new InterpolationBilinear();
    >           else if(interpolation.equals("INTERPOLATION_BICUBIC"))
    >       	    interp = new InterpolationBicubic(8);
    >           else if(interpolation.equals("INTERPOLATION_BICUBIC2"))
    >                   interp = new InterpolationBicubic2(8);
    >
    >            // Create a ParameterBlock
    >            ParameterBlock pb = new ParameterBlock();
    >                 pb.addSource(input);                   // The source imag
   e
    >                 pb.add((float)Math.max(x_trans, 0));    // The x
    > translation
    >                 pb.add((float)Math.max(y_trans, 0));    // The y
    > translation
    >                 pb.add(interp); // The interpolation
    >
    >            // Create the translate operation
    >            PlanarImage output = JAI.create("translate", pb, null);
    >
    >            imgDest.broadcast(new ObjectToken(output));
    >
    >
    >         }
    >
    >         /**
    >          * Post fire the actor. Return false to indicate that the
    >          * process has finished. If it returns true, the process will
    >          * continue indefinitely.
    >          *
    >          *@return
    >          */
    >         public boolean postfire()
    >         {
    >           return false;
    >         }
    >
    >         /**
    >          * Pre fire the actor.
    >          *  Calls the super class's prefire in case something is set
    > there.
    >          *
    >          *@return
    >          *@exception  IllegalActionException
    >          */
    >         public boolean prefire()
    >           throws IllegalActionException
    >         {
    >           return super.prefire();
    >         }
    >
    >
    >
    >
    >       }
    >
    >
    >
    >     _______________________________________________
    >     Kepler-cvs mailing list
    >     Kepler-cvs at ecoinformatics.org
    >     http://mercury.nceas.ucsb.edu/ecoinformatics/mailman/listinfo/kepler-
   cvs
    > --------
    > _______________________________________________
    > Kepler-dev mailing list
    > Kepler-dev at ecoinformatics.org
    > http://mercury.nceas.ucsb.edu/ecoinformatics/mailman/listinfo/kepler-dev
    >
    
--------


More information about the Kepler-dev mailing list