net.grelf.grip
Class Accumulator

java.lang.Object
  extended by net.grelf.grip.Accumulator

public class Accumulator
extends java.lang.Object

For adding or averaging images, a data store with 32 bits per pixel per channel to prevent overflow. This needs a lot of memory of course: width x height x 12 bytes for 3-channel images. The data can be saved on disc and reloaded. This uses a GRIP-specific format comprising a text header followed by binary pixel data. The header is Java 2-bytes-per-character text strings, each preceded by an int containing the number of characters in the string. Each string except the first contains an equals sign (=) after which are the digits of a value. There are no line end characters or other formatting. The strings are (UTF-8 encoding): GRIP v... width(px)=... height(px)=... channels=... bitsPerChannel=32 min=... max=... where the first string contains the GRIP version number and min and max show the overall range of values occurring (across all channels). The binary pixel data are stored as int values, in the usual Java big-endian format, in this order: for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int b = 0; b < nBands; b++) { dos.writeInt (accum [x][y][b]); // dos is a java.io.DataOutputStream } } }


Constructor Summary
Accumulator(java.awt.image.BufferedImage bim)
          Use the BufferedImage to set the width, height and number of bands (channels) in the accumulator.
Accumulator(int width, int height, int nBands)
           
Accumulator(java.lang.String filePath)
          Reload an accumulator that has previously been saved on disc by GRIP.
 
Method Summary
 void add(java.awt.image.BufferedImage bim)
          Add pixel values from bim into the accumulator array.
 void add(java.awt.image.BufferedImage bim, double dx, double dy)
          Add pixel values from bim into the accumulator array, offset by vector (dx, dy).
 void add(java.awt.image.BufferedImage bim, int dx, int dy)
          Add pixel values from bim into the accumulator array, offset by vector (dx, dy).
 void applyCurve(RangeInt currentRange, java.util.List<java.awt.Point> points, java.awt.image.BufferedImage bim)
          Apply a look-up curve to transform accumulator pixels into BufferedImage pixels.
 boolean averageShiftAccumulate(java.awt.image.BufferedImage bim, int imNo, int middleImNo, java.util.List<MatchPair> matches, BlobMeas[][] lookup, int nBrightest)
          For image imNo of a sequence, add the pixel values into the accumulator but first shift the image so that matched point pairs are superimposed.
 boolean brightestShiftAccumulate(java.awt.image.BufferedImage bim, int imNo, int middleImNo, java.util.List<PointFloat> centres)
          For image imNo of a sequence, add the pixel values into the accumulator but first shift the image so that brightest objects in this image and the middle image of the sequence are superimposed.
9.11.26: changed last parameter from BlobMeas [][] lookup.
 void divide(int n)
          Divide all pixel values (in all bands) in the accumulator by n.
 void drawImage(ImFrame imf)
          Convert the accumulator data into a BufferedImage, by drawing them into the image displayed in an ImFrame.
 int getBitsPerChannel()
          Get the number of bits per channel; currently always returns 32.
 RangeInt[] getChannelRanges()
          Find the range of values in each channel.
 int getHeight()
          Get the height, in pixels, of the accumulator.
 int getNBands()
          Get the number of bands (channels) in the accumulator.
 RangeInt getOverallRange()
          Get overall range of values across all channels.
 int[] getPixel(int x, int y)
          Get array of pixel values for all bands at the given (x, y) position.
 RangeInt getRange()
          Get the minumum and maximum values occurring, across all channels.
 int getWidth()
          Get the width, in pixels, of the accumulator.
static boolean isAccumFile(java.lang.String path)
          Read the start of a file to find out whether it is a saved Accumulator.
 RangeInt load(java.lang.String filePath)
          Load from an Accumulator file previously saved on disc by GRIP.
 void save(java.lang.String filePath)
          Save on disc: slower version, has to work out the range of values occurring in the accumulator.
 void save(java.lang.String filePath, RangeInt range)
          Save on disc: faster version if the range of values occurring in the accumulator is already known.
 void scale(RangeInt[] currentChannelRanges, java.awt.image.BufferedImage bim)
          Offset and scale all values to fit into the supplied image.
 void scale(RangeInt[] currentChannelRanges, RangeInt[] targetChannelRanges)
          Offset and scale all values to fit in the given target ranges.
 void set(java.awt.image.BufferedImage bim)
          Set pixel values from bim into the accumulator array.
 void subtract(java.awt.image.BufferedImage bim)
          Subtract pixel values of bim from the accumulator array.
 java.lang.String toString()
          Get a simple description : wd x ht x channels
 boolean warpAccumulate(java.awt.image.BufferedImage bim, int imNo, int middleImNo, java.util.List<MatchPair> matches, BlobMeas[][] lookup, int nBrightest)
          For image imNo of a sequence, add the pixel values into the accumulator but first distort the image so that matched point pairs are superimposed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Accumulator

public Accumulator(int width,
                   int height,
                   int nBands)

Accumulator

public Accumulator(java.awt.image.BufferedImage bim)
            throws IncompatibleImageException
Use the BufferedImage to set the width, height and number of bands (channels) in the accumulator. Populate the pixel values in the accumulator from the image also.

Throws:
IncompatibleImageException

Accumulator

public Accumulator(java.lang.String filePath)
Reload an accumulator that has previously been saved on disc by GRIP.

Method Detail

getWidth

public int getWidth()
Get the width, in pixels, of the accumulator.


getHeight

public int getHeight()
Get the height, in pixels, of the accumulator.


getNBands

public int getNBands()
Get the number of bands (channels) in the accumulator.


getBitsPerChannel

public int getBitsPerChannel()
Get the number of bits per channel; currently always returns 32.


getRange

public RangeInt getRange()
Get the minumum and maximum values occurring, across all channels.


toString

public java.lang.String toString()
Get a simple description : wd x ht x channels

Overrides:
toString in class java.lang.Object

add

public void add(java.awt.image.BufferedImage bim)
         throws IncompatibleImageException
Add pixel values from bim into the accumulator array. If bim is larger than the accumulator then the rectangle starting at the top left corner of bim which overlaps the accumulator will be used.

Throws:
IncompatibleImageException

add

public void add(java.awt.image.BufferedImage bim,
                int dx,
                int dy)
         throws IncompatibleImageException
Add pixel values from bim into the accumulator array, offset by vector (dx, dy). Only those pixels of the offset bim which overlap the accumulator are used. using integer coordinates, this version is fast but does not interpolate from the source image.

Throws:
IncompatibleImageException

add

public void add(java.awt.image.BufferedImage bim,
                double dx,
                double dy)
         throws IncompatibleImageException
Add pixel values from bim into the accumulator array, offset by vector (dx, dy). Only those pixels of the offset bim which overlap the accumulator are used. Using double coordinates, this version is slower but does interpolate from the source image.

Throws:
IncompatibleImageException

applyCurve

public void applyCurve(RangeInt currentRange,
                       java.util.List<java.awt.Point> points,
                       java.awt.image.BufferedImage bim)
                throws IncompatibleImageException
Apply a look-up curve to transform accumulator pixels into BufferedImage pixels. The curve is a set of points with x and y ranges of 0..255 but the accumulator (x-axis) has 32-bit range and the target image (y-axis) may have any number of bits per channel. The accumulator and image must have the same number of channels, otherwise an IncompatibleImageException is thrown.

Throws:
IncompatibleImageException

divide

public void divide(int n)
Divide all pixel values (in all bands) in the accumulator by n.


drawImage

public void drawImage(ImFrame imf)
Convert the accumulator data into a BufferedImage, by drawing them into the image displayed in an ImFrame. This does not throw an exception if the accumulator is not the same size as the ImFrame, on the grounds that the user will see the result. Assumes that the bit depth of the BufferedImage is enough to hold the maximum value in the Accumulator. If that is not the case pixels will overflow, so consider using ImCurveDialogue.askCurve (imf, accum) instead, to allow the user to scale the data into the required range.


getChannelRanges

public RangeInt[] getChannelRanges()
Find the range of values in each channel. New Nov 07.


getOverallRange

public RangeInt getOverallRange()
Get overall range of values across all channels. New Nov 07.


getPixel

public int[] getPixel(int x,
                      int y)
Get array of pixel values for all bands at the given (x, y) position. Returns all zeroes if the position is outside the accumulator array.


isAccumFile

public static boolean isAccumFile(java.lang.String path)
Read the start of a file to find out whether it is a saved Accumulator.


load

public RangeInt load(java.lang.String filePath)
Load from an Accumulator file previously saved on disc by GRIP. Returns the overall range of values occurring (across all channels).


save

public void save(java.lang.String filePath)
Save on disc: slower version, has to work out the range of values occurring in the accumulator.


save

public void save(java.lang.String filePath,
                 RangeInt range)
Save on disc: faster version if the range of values occurring in the accumulator is already known.


scale

public void scale(RangeInt[] currentChannelRanges,
                  RangeInt[] targetChannelRanges)
Offset and scale all values to fit in the given target ranges. Both input arrays must have the same number of dimensions, equal to the number of channels. New Nov 07.


scale

public void scale(RangeInt[] currentChannelRanges,
                  java.awt.image.BufferedImage bim)
           throws IncompatibleImageException
Offset and scale all values to fit into the supplied image. The input array must have the same number of dimensions as the number of channels. The image must have the same number of channels as the accumulator, otherwise an IncompatibleImageException is thrown. New Nov 09.

Throws:
IncompatibleImageException

set

public void set(java.awt.image.BufferedImage bim)
         throws IncompatibleImageException
Set pixel values from bim into the accumulator array. If bim is larger than the accummulator then the rectangle starting at the top left corner of bim which overlaps the accumulator will be used.

Throws:
IncompatibleImageException

subtract

public void subtract(java.awt.image.BufferedImage bim)
              throws IncompatibleImageException
Subtract pixel values of bim from the accumulator array. If bim is larger than the accumulator then the rectangle starting at the top left corner of bim which overlaps the accumulator will be used.

Throws:
IncompatibleImageException

brightestShiftAccumulate

public boolean brightestShiftAccumulate(java.awt.image.BufferedImage bim,
                                        int imNo,
                                        int middleImNo,
                                        java.util.List<PointFloat> centres)
                                 throws IncompatibleImageException
For image imNo of a sequence, add the pixel values into the accumulator but first shift the image so that brightest objects in this image and the middle image of the sequence are superimposed.
9.11.26: changed last parameter from BlobMeas [][] lookup. The reason for this is that when matching on single bright objects we may mean the moon, nearly filling the image, in which case we would run out of memory if holding all details of that for every image in a sequence.

Throws:
IncompatibleImageException

averageShiftAccumulate

public boolean averageShiftAccumulate(java.awt.image.BufferedImage bim,
                                      int imNo,
                                      int middleImNo,
                                      java.util.List<MatchPair> matches,
                                      BlobMeas[][] lookup,
                                      int nBrightest)
                               throws IncompatibleImageException
For image imNo of a sequence, add the pixel values into the accumulator but first shift the image so that matched point pairs are superimposed. Use the average translation vector from all matched objects.

Throws:
IncompatibleImageException

warpAccumulate

public boolean warpAccumulate(java.awt.image.BufferedImage bim,
                              int imNo,
                              int middleImNo,
                              java.util.List<MatchPair> matches,
                              BlobMeas[][] lookup,
                              int nBrightest)
                       throws IncompatibleImageException
For image imNo of a sequence, add the pixel values into the accumulator but first distort the image so that matched point pairs are superimposed. Return false if not able to warp the image.

Throws:
IncompatibleImageException