/** * StarField instance contains the image array and related information * Glen Cowan, RHUL Physics Department * December 2003 */ import java.util.*; import java.math.*; public class StarField { // private data fields private int nx, ny; private int minVal; // the threshold private double gain; private double mode; private double median; private Pixel[][] pixelArray; protected Vector clusterVec; // constructors public StarField(){ nx = 0; ny = 0; minVal = 0; gain = 1.0; mode = 0.0; median = 0.0; clusterVec = new Vector(); } public StarField(int nx, int ny){ this(); this.nx = nx; this.ny = ny; pixelArray = new Pixel[nx][ny]; for (int j=0; j= minVal & cNum < 0; if ( startCluster ){ clusterNum++; // start counting at 0 Cluster c = new Cluster(clusterNum); c.addPixel(pixelArray[i][j]); Stack s = new Stack(); s.push(pixelArray[i][j]); boolean clusterFinished = s.empty(); while ( ! clusterFinished ) { // Consider neighbouring pixels; if over minVal push on stack and add to cluster Pixel p = (Pixel)s.pop(); int pI = p.getI(); int pJ = p.getJ(); if (pI > 0) { considerPixel(pixelArray[pI-1][pJ], s, c, minVal); } if (pI < nx-1) { considerPixel(pixelArray[pI+1][pJ], s, c, minVal); } if (pJ > 0) { considerPixel(pixelArray[pI][pJ-1], s, c, minVal); } if (pJ < ny-1) { considerPixel(pixelArray[pI][pJ+1], s, c, minVal); } // Should we consider the corner neighbours? If not, perhaps rethink peak finding algo. // // if (pI>0 && pJ>0) { considerPixel(pixelArray[pI-1][pJ-1], s, c, minVal); } // if (pI0) { considerPixel(pixelArray[pI+1][pJ-1], s, c, minVal); } // if (pI>0 && pJ= minVal ) { s.push(n); int cNum = c.getClusterNum(); n.setCluster(cNum); c.addPixel(n); } } // end of considerPixel } // end of class StarField //------------------------------------------------------------------------- class Cluster { // A cluster is a contiguous set of pixels with values of at least // a minimum threshold. A peak is a (possibly local) maximum. private Vector pixelVec; private int clusterNum; private Vector peakVec; private Star star; // Constructors public Cluster(){ pixelVec = new Vector(); clusterNum = -1; peakVec = new Vector(); Star s = new Star(-1, -1, -1); setStar(s); } public Cluster(Vector pixelVec){ this(); this.pixelVec = pixelVec; if ( pixelVec.size() > 0 ) { clusterNum = ((Pixel)pixelVec.elementAt(0)).getCluster(); } else { System.out.println("Cluster>> pixelVec has no entries"); clusterNum = -1; } } public Cluster(int clusterNum){ this(); pixelVec = new Vector(); this.clusterNum = clusterNum; } public Cluster(Vector pixelVec, int clusterNum){ this(); this.pixelVec = pixelVec; this.clusterNum = clusterNum; } // public methods public int numPixels(){ return pixelVec.size(); } public Vector getPixelVec(){ return pixelVec; } public int getClusterNum(){ return clusterNum; } public Vector getPeakVec(){ return peakVec; } public void addPixel(Pixel p){ pixelVec.addElement(p); p.setCluster(clusterNum); // recall clusterNum is private data of Pixel } public void addPeak(Pixel pix){ peakVec.addElement(pix); if ( pix.getCluster() != clusterNum ) { System.out.println("Cluster.addPeak>> peak cluster number doesn't match"); pix.setCluster(clusterNum); } } public void setClusterNum(int clusterNum){ this.clusterNum = clusterNum; } public int totalCounts(){ int counts = 0; for (int i = 0; i val1 ){ comp = -1; } else { comp = 0; } return comp; } // end of compareTo } // end of class Star