Re: extracting data from image

I said:

> and that can use the rectangle bounds to construct
> a new Gridded2DSet for the image region of interest,

Or even simpler, construct a Linear2DSet from the rectangle
bounds.  Modifying the CellImpl in the main() method of
visad/bom/, the code might
look something like:

    final FlatField image = ... // your original image
    final int size = ... // desired number of lines and
                         // elements in sub_image
    CellImpl cell = new CellImpl() {
      public void doAction() throws VisADException, RemoteException {
        Set set = (Set) ref.getData();
        float[][] samples = set.getSamples();
        if (samples != null) {
          Linear2DSet sub_set
            new Linear2DSet(set.getType(),
                            samples[0][0], samples[0][1], size,
                            samples[1][0], samples[1][1], size);
          FlatField sub_image = image.resample(sub_set);
          // now sub_image contains the user-selected rectangular
          // image region, resampled to (size x size) pixels

If you want sub_image to contain exactly those pixels of image
within the region (i.e., no interpolation), then you'll need to
construct sub_set as those samples in image.getDomainSet() that
lie inside:

  (samples[0][0], samples[0][1]) x (samples[1][0], samples[1][1])

If image.getDomainSet() is a Linear2DSet that won't be too
difficult, but if its a general Gridded2DSet or Irregular2DSet,
then that will be a bit complex.

Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738