Commit in CDMS/src/CDMS/Partridge/FieldFlattening on MAIN
BlankImageFinder.java+3-41.3 -> 1.4
FieldFlattener.java+94-471.3 -> 1.4
FieldFlattenerTest.java+3-11.4 -> 1.5
ImageQuadrant.java+74-51.1 -> 1.2
+174-57
4 modified files
Added Javadoc, ability to set target intensity

CDMS/src/CDMS/Partridge/FieldFlattening
BlankImageFinder.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- BlankImageFinder.java	9 Apr 2011 17:22:14 -0000	1.3
+++ BlankImageFinder.java	10 Apr 2011 17:30:26 -0000	1.4
@@ -14,8 +14,8 @@
 import java.util.List;
 
 /**
- * Find blank images by identifying images with small standard deviations
- * for the pixels in the image.
+ * Find blank image quadrants by identifying quadrants with small standard deviations
+ * for the pixels in the quadrant.
  *
  * @author Richard Partridge
  */
@@ -28,13 +28,13 @@
         String fbase = "c:/CDMS/MaxScanTestL09/MaxScanTestL09-";
         int ifirst = 1;
         int ilast = 138;
-        int nfile = ilast - ifirst + 1;
         String suffix = ".BMP";
         String outfile = "c:/CDMS/MaxScanTestL09_blanks.txt";
         double imin = 100.;
         int nblank = 10;
 
         //  Create arrays to hold the mean and sd calculations
+        int nfile = ilast - ifirst + 1;
         double[][] imean = new double[nfile][4];
         double[][] isd = new double[nfile][4];
 
@@ -60,7 +60,6 @@
                 double i2tot = 0.;
                 for (int row=0; row<nrow; row++) {
                     for (int col=0; col<ncol; col++) {
-
                         int irow = ImageQuadrant.getIRow(row, nrow, quad);
                         int icol = ImageQuadrant.getICol(col, ncol, quad);
                         double intensity = image.getIntensity(irow, icol);

CDMS/src/CDMS/Partridge/FieldFlattening
FieldFlattener.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- FieldFlattener.java	9 Apr 2011 17:22:14 -0000	1.3
+++ FieldFlattener.java	10 Apr 2011 17:30:26 -0000	1.4
@@ -33,15 +33,21 @@
     private List<ImageQuadrant> _quads;
     private int _nrow;
     private int _ncol;
+    private double[][][] _ared;
+    private double[][][] _agreen;
+    private double[][][] _ablue;
     private double[][] _rcor;
     private double[][] _gcor;
     private double[][] _bcor;
+    private double _rtarget;
+    private double _gtarget;
+    private double _btarget;
     private int _max_iterations = 10;
 
     /**
-     *  Fully qualified constructor
+     *  Fully qualified constructor.
      *
-     * @param blankfile file containing the list of blank images
+     * @param blankfile file containing the list of blank image quadrants
      * @param cut number of std dev used for the outlier removal cut
      */
     public FieldFlattener(String blankfile, double cut) {
@@ -52,26 +58,24 @@
         //  Initialize the arrays for the image data and pixel descriptors
         if (_quads.isEmpty()) throw new RuntimeException("No blank image quadrants found");
 
-        //  Create arrays for the average color intensities of each pixel
-        double ared[][][] = new double[_nrow][_ncol][4];
-        double agreen[][][] = new double[_nrow][_ncol][4];
-        double ablue[][][] = new double[_nrow][_ncol][4];
-        int nquad[] = {0, 0, 0, 0};
-
-        //  Count the number of images for each quadrant
-        for (ImageQuadrant iquad : _quads) {
-            int quad = iquad.getQuadrant();
-            nquad[quad] += 1;
-        }
+        //  Create arrays for the average color intensities of each pixel/quadrant
+        _ared = new double[_nrow][_ncol][4];
+        _agreen = new double[_nrow][_ncol][4];
+        _ablue = new double[_nrow][_ncol][4];
+
+        //  Create the arrays to hold the field flattening map
+        _rcor = new double[2*_nrow][2*_ncol];
+        _gcor = new double[2*_nrow][2*_ncol];
+        _bcor = new double[2*_nrow][2*_ncol];
 
-        //  Loop over the quadrants
+        //  Find the average color intensities - first loop over the quadrants
         for (int quad=0; quad<4; quad++) {
 
             //  Loop over all pixels in a quadrant
             for (int row=0; row<_nrow; row++) {
                 for (int col=0; col<_ncol; col++) {
 
-                    //  Lists for the color intensities
+                    //  Lists for the color intensities of this pixel
                     List<Integer> red = new ArrayList<Integer>();
                     List<Integer> green = new ArrayList<Integer>();
                     List<Integer> blue = new ArrayList<Integer>();
@@ -91,49 +95,31 @@
                     //  Average the color intensities for this pixel using a
                     //  truncated mean that discards outliers since our blank
                     //  images may not be flawless
-                    ared[row][col][quad] = TruncatedMean(red, cut);
-                    ablue[row][col][quad] = TruncatedMean(blue, cut);
-                    agreen[row][col][quad] = TruncatedMean(green, cut);
+                    _ared[row][col][quad] = TruncatedMean(red, cut);
+                    _agreen[row][col][quad] = TruncatedMean(green, cut);
+                    _ablue[row][col][quad] = TruncatedMean(blue, cut);
                 }
             }
         }
 
-        //  Find the global average values of each color intensity averaging over
-        //  the entire image the color intensities that were averaged
+        //  Find the global average values of each color intensity by averaging
+        //  over the entire image
         double rave = 0.;
         double gave = 0.;
         double bave = 0.;
         for (int row=0; row<_nrow; row++) {
             for (int col=0; col<_ncol; col++) {
                 for (int quad=0; quad<4; quad++) {
-                    rave += ared[row][col][quad] / (4 * _nrow * _ncol);
-                    gave += agreen[row][col][quad] / (4 * _nrow * _ncol);
-                    bave += ablue[row][col][quad] / (4 * _nrow * _ncol);
+                    rave += _ared[row][col][quad] / (4 * _nrow * _ncol);
+                    gave += _agreen[row][col][quad] / (4 * _nrow * _ncol);
+                    bave += _ablue[row][col][quad] / (4 * _nrow * _ncol);
                 }
             }
         }
 
-        //  Create the arrays to hold the field flattening map
-        _rcor = new double[2*_nrow][2*_ncol];
-        _gcor = new double[2*_nrow][2*_ncol];
-        _bcor = new double[2*_nrow][2*_ncol];
-
-        //  Calculate the correction factors to be applied to the
-        //  color intensities for each image pixel
-        for (int row=0; row<_nrow; row++) {
-            for (int col=0; col<_ncol; col++) {
-                for (int quad=0; quad<4; quad++) {
-
-                    //  Get the row/col for the full 4-quadrant image
-                    int irow = ImageQuadrant.getIRow(row, _nrow, quad);
-                    int icol = ImageQuadrant.getICol(col, _ncol, quad);
+        //  Set the correction factors to target the global average color intensities
+        setTarget(rave, bave, gave);
 
-                    _rcor[irow][icol] = rave / ared[row][col][quad];
-                    _gcor[irow][icol] = gave / agreen[row][col][quad];
-                    _bcor[irow][icol] = bave / ablue[row][col][quad];
-                }
-            }
-        }
     }
 
     /**
@@ -173,6 +159,67 @@
     }
 
     /**
+     * Return the target value for the red component of a blank image.
+     * 
+     * @return red target intensity
+     */
+    public double getRedTarget() {
+        return _rtarget;
+    }
+
+    /**
+     * Return the target value for the green component of a blank image.
+     *
+     * @return green target intensity
+     */
+    public double getGreenTarget() {
+        return _gtarget;
+    }
+
+    /**
+     * Return the target value for the blue component of a blank image.
+     *
+     * @return blue target intensity
+     */
+    public double getBlueTarget() {
+        return _btarget;
+    }
+
+    /**
+     * Set the target color intensities for a blank image.  The field flattening
+     * correction factors are recalculated to achieve, on average, these target
+     * color intensities for blank regions.
+     *
+     * @param rtarget red target intensity
+     * @param gtarget green target intensity
+     * @param btarget blue target intensity
+     */
+    public void setTarget(double rtarget, double gtarget, double btarget) {
+
+        //  Save the target color intensities
+        _rtarget = rtarget;
+        _gtarget = gtarget;
+        _btarget = btarget;
+
+        //  Calculate the correction factors to be applied to the
+        //  color intensities for each image pixel
+        for (int row=0; row<_nrow; row++) {
+            for (int col=0; col<_ncol; col++) {
+                for (int quad=0; quad<4; quad++) {
+
+                    //  Get the row/col for the full 4-quadrant image
+                    int irow = ImageQuadrant.getIRow(row, _nrow, quad);
+                    int icol = ImageQuadrant.getICol(col, _ncol, quad);
+
+                    _rcor[irow][icol] = _rtarget / _ared[row][col][quad];
+                    _gcor[irow][icol] = _gtarget / _agreen[row][col][quad];
+                    _bcor[irow][icol] = _btarget / _ablue[row][col][quad];
+                }
+            }
+        }
+    }
+
+    /**
      * Return the list of blank image files used to construct the field
      * flattening correction.
      *
@@ -221,9 +268,9 @@
     }
 
     /**
-     * Read and parse the blank image file.
+     * Read and parse the blank image quadrant file.
      *
-     * @param blankfile file containing the list of blank images
+     * @param blankfile file containing the list of blank image quadrants
      */
     private void ReadBlankFile(String blankfile) {
 
@@ -289,7 +336,7 @@
     }
 
     /**
-     * Calculated the truncated mean from an array of values.  The algorithm
+     * Calculated the truncated mean from a list of values.  The algorithm
      * is an iterative one, where initially all values are included in the
      * calculation of the mean and stddev, but in subsequent iterations those
      * values that are more than cut * stddev away from the last mean are not
@@ -298,7 +345,7 @@
      * iterations is reached (to handle cases where the result ping-pongs
      * between two or more values).
      *
-     * @param values array of values to be averaged
+     * @param values list of values to be averaged
      * @param cut truncation cut in units of the standard deviation
      * @return truncated mean
      */

CDMS/src/CDMS/Partridge/FieldFlattening
FieldFlattenerTest.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- FieldFlattenerTest.java	9 Apr 2011 17:22:14 -0000	1.4
+++ FieldFlattenerTest.java	10 Apr 2011 17:30:26 -0000	1.5
@@ -21,6 +21,8 @@
 
         String blankindexfile = "c:/CDMS/MaxScanTestL09_blanks.txt";
         FieldFlattener flat = new FieldFlattener(blankindexfile, 2.0);
+        flat.setTarget(flat.getRedTarget()+ 20, flat.getGreenTarget()+20,
+                flat.getBlueTarget()+20);
         int ifile = 0;
         AIDA aida = AIDA.defaultInstance();
         for (ImageQuadrant iquad : flat.getBlankImageQuadrants()) {
@@ -57,7 +59,7 @@
             double sd = Math.sqrt(i2sum/npixel - mean*mean);
             System.out.println("Original file: "+fname+" mean: "+mean+" sd: "+sd);
             String otype = "png";
-            File outfile = new File("c:/CDMS/flattened"+ifile+"."+otype);
+            File outfile = new File("c:/CDMS/flattened"+ifile+"bright."+otype);
             ifile++;
             ImageIO.write(flatimage.getBufferedImage(), otype, outfile);
 

CDMS/src/CDMS/Partridge/FieldFlattening
ImageQuadrant.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ImageQuadrant.java	9 Apr 2011 17:22:14 -0000	1.1
+++ ImageQuadrant.java	10 Apr 2011 17:30:26 -0000	1.2
@@ -18,28 +18,39 @@
  *
  * @author Richard Partridge
  * @date Apr 8, 2011
- * @version $Id: ImageQuadrant.java,v 1.1 2011/04/09 17:22:14 partridge Exp $
+ * @version $Id: ImageQuadrant.java,v 1.2 2011/04/10 17:30:26 partridge Exp $
  */
 public class ImageQuadrant {
 
     private String _fname;
     private int _quad;
-    private PixelArray _pixarray;
     private int _ncol;
     private int _nrow;
     private int[][] _red;
     private int[][] _green;
     private int[][] _blue;
 
+    /**
+     * Instantiate an ImageQuadrant by specifying an image file and the
+     * desired quadrant.
+     *
+     * @param fname image file name
+     * @param quad quadrant (0=UL, 1=UR, 2=LL, 3=LR)
+     */
     public ImageQuadrant(String fname, int quad) {
+
+        //  Save the file name and quadrant, check for valid quadrant number
         _fname = fname;
         _quad = quad;
         if (_quad < 0 || _quad > 3) throw new RuntimeException("Invalid quadrant: "+_quad);
 
+        //  Retrieve the image with an arbitrary origin and pixel sizes
         GeImage image = new GeImage(fname, 0., 0., 1., 1.);
-        _pixarray = image.getPixelArray();
-        _nrow = _pixarray.getNRow() / 2;
-        _ncol = _pixarray.getNCol() / 2;
+
+        //  Get the size of the quadrant
+        PixelArray pixarray = image.getPixelArray();
+        _nrow = pixarray.getNRow() / 2;
+        _ncol = pixarray.getNCol() / 2;
 
         //  Create arrays for the color intensities of each pixel
         _red = new int[_nrow][_ncol];
@@ -63,39 +74,97 @@
         }
     }
 
+    /**
+     * Return the quadrant number.
+     *
+     * @return quadrant number
+     */
     public int getQuadrant() {
         return _quad;
     }
 
+    /**
+     * Return the image file name.
+     *
+     * @return image file name
+     */
     public String getFileName() {
         return _fname;
     }
 
+    /**
+     * Return the number of rows for this quadrant.
+     *
+     * @return number of rows
+     */
     public int getNRow() {
         return _nrow;
     }
 
+    /**
+     * Return the number of columns for this quadrant.
+     *
+     * @return number of columns
+     */
     public int getNCol() {
         return _ncol;
     }
 
+    /**
+     * Return the red image data for a specified pixel.
+     *
+     * @param row row number
+     * @param col column number
+     * @return red intensity
+     */
     public int getRed(int row, int col) {
         return _red[row][col];
     }
 
+     /**
+     * Return the green image data for a specified pixel.
+     *
+     * @param row row number
+     * @param col column number
+     * @return green intensity
+     */
     public int getGreen(int row, int col) {
         return _green[row][col];
     }
+
+     /**
+     * Return the blue image data for a specified pixel.
+     *
+     * @param row row number
+     * @param col column number
+     * @return blue intensity
+     */
     public int getBlue(int row, int col) {
         return _blue[row][col];
     }
 
+    /**
+     * Return the image row number corresponding to a given quadrant row.
+     *
+     * @param row quadrant row
+     * @param nrow number of rows in a quadrant
+     * @param quad quadrant number
+     * @return row number in full (4 quadrant) image
+     */
     public static int getIRow(int row, int nrow, int quad) {
         int irow = row;
         if (quad > 1) irow += nrow;
         return irow;
     }
 
+    /**
+     * Return the column number corresponding to a given quadrant column.
+     *
+     * @param col quadrant column
+     * @param ncol number of columns in a quadrant
+     * @param quad quadrant number
+     * @return column number in a full (4 quadrant) image
+     */
     public static int getICol(int col, int ncol, int quad) {
         int icol = col;
         if (quad == 1 || quad == 3) icol += ncol;
CVSspam 0.2.8