3 removed + 4 modified, total 7 files
CDMS/src/CDMS/Partridge/ImageComparison
diff -u -r1.1 -r1.2
--- Cluster.java 5 Sep 2010 20:20:10 -0000 1.1
+++ Cluster.java 4 Oct 2010 22:50:36 -0000 1.2
@@ -4,6 +4,7 @@
package CDMS.Partridge.ImageComparison;
+import CDMS.Partridge.ImageUtils.PixelArray;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
CDMS/src/CDMS/Partridge/ImageComparison
diff -u -r1.1 -r1.2
--- CompareImages.java 5 Sep 2010 20:20:10 -0000 1.1
+++ CompareImages.java 4 Oct 2010 22:50:36 -0000 1.2
@@ -4,6 +4,9 @@
package CDMS.Partridge.ImageComparison;
+import CDMS.Partridge.ImageUtils.ImageData;
+import CDMS.Partridge.ImageUtils.PixelArray;
+import CDMS.Partridge.ImageUtils.ImageDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -110,14 +113,15 @@
ImageData testimage = test.getImageData();
ImageData refimage = ref.getImageData();
PixelArray pixarray = test.getPixelArray();
- for (int row=0; row<pixarray.getNRow(); row++) {
- for (int col=0; col<pixarray.getNCol(); col++) {
- int refrgb = refimage.getRGB(row, col);
- int testrgb = testimage.getRGB(row, col);
- int dblue = refimage.getBlue(refrgb) - testimage.getBlue(testrgb);
- int dgreen = refimage.getGreen(refrgb) - testimage.getGreen(testrgb);
- int dred = refimage.getRed(refrgb) - testimage.getGreen(testrgb);
- double deviation = Math.sqrt((dblue*dblue + dgreen*dgreen + dred*dred) / 3.);
+ for (int row=20; row<pixarray.getNRow()-20; row++) {
+ for (int col=20; col<pixarray.getNCol()-20; col++) {
+// int refrgb = refimage.getRGB(row, col);
+// int testrgb = testimage.getRGB(row, col);
+// int dblue = refimage.getBlue(refrgb) - testimage.getBlue(testrgb);
+// int dgreen = refimage.getGreen(refrgb) - testimage.getGreen(testrgb);
+// int dred = refimage.getRed(refrgb) - testimage.getGreen(testrgb);
+// double deviation = Math.sqrt((dblue*dblue + dgreen*dgreen + dred*dred) / 3.);
+ double deviation = refimage.getIntensity(row+2, col+1) - testimage.getIntensity(row, col);
if (Math.abs(deviation) > _neighbor_threshold) {
long pixel = pixarray.getPixel(row, col);
double x = pixarray.getX(pixel);
CDMS/src/CDMS/Partridge/ImageComparison
diff -u -r1.1 -r1.2
--- ImageComparison.java 6 Sep 2010 20:30:43 -0000 1.1
+++ ImageComparison.java 4 Oct 2010 22:50:36 -0000 1.2
@@ -4,6 +4,8 @@
package CDMS.Partridge.ImageComparison;
+import CDMS.Partridge.ImageUtils.PixelArray;
+import CDMS.Partridge.ImageUtils.ImageDescriptor;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -23,8 +25,8 @@
public static void main(String[] args) throws IOException {
- String fname1 = "c:/CDMS/IZipG47_Side1_PKG/IZipG47_Side1_PKG-6509.png";
- String fname2 = "c:/CDMS/IZipG47_Side1_PKG/IZipG47_Side1_PKG-6510.png";
+ String fname1 = "c:/CDMS/IZipG47_Side1_PKG/IZipG47_Side1_PKG-4293.png";
+ String fname2 = "c:/CDMS/IZipG16K_Side1/IZipG16K_Side1-4293.png";
int id = 1;
double xc = 0.;
double yc = 0.;
@@ -67,7 +69,7 @@
}
}
System.out.println("Clustered pixels: "+tot);
- File outfile = new File("c:/CDMS/ClusterTestSeed-seed"+seed_threshold+"nbr"+nbr_threshold+".png");
+ File outfile = new File("c:/CDMS/ClusterTestSeed-seed"+seed_threshold+"nbr"+nbr_threshold+"true.png");
ImageIO.write(buf, "png", outfile);
CDMS/src/CDMS/Partridge/ImageComparison
diff -u -r1.2 -r1.3
--- NearestNeighborClustering.java 5 Sep 2010 20:20:10 -0000 1.2
+++ NearestNeighborClustering.java 4 Oct 2010 22:50:36 -0000 1.3
@@ -3,6 +3,7 @@
*/
package CDMS.Partridge.ImageComparison;
+import CDMS.Partridge.ImageUtils.PixelArray;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
CDMS/src/CDMS/Partridge/ImageComparison
diff -N ImageData.java
--- ImageData.java 6 Sep 2010 20:30:43 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,222 +0,0 @@
-/*
- * ImageData.java
- */
-package CDMS.Partridge.ImageComparison;
-
-import java.awt.image.BufferedImage;
-
-/**
- * Encapsulate the RGB color information associated with an image.
- *
- * @author Richard Partridge
- */
-public class ImageData {
-
- private PixelArray _pixarray;
- private int[][] _RGB;
-
- /**
- * Construct an empty image.
- *
- * @param pixarray pixel array descriptor
- */
- public ImageData(PixelArray pixarray) {
- _pixarray = pixarray;
- _RGB = new int[pixarray.getNRow()][pixarray.getNCol()];
- }
-
- /**
- * Construct an image using the RGB data contained in a BufferedImage
- *
- * @param pixarray pixel array descriptor
- * @param image image
- */
- public ImageData(PixelArray pixarray, BufferedImage image) {
- this(pixarray);
-
- // Check that the image sizes match
- if (_pixarray.getNRow() != image.getHeight() || _pixarray.getNCol() != image.getWidth())
- throw new RuntimeException("Image size does not match pixel array descriptor");
-
- // Translate the image data into the RGB scheme used for the CDMS image analysis and
- // store it locally
- for (int row=0; row<_pixarray.getNRow(); row++) {
- for (int col=0; col<_pixarray.getNCol(); col++) {
- int RGB = image.getRGB(col, row);
- _RGB[row][col] = translateBufferedImageRGB(RGB);
- }
- }
- }
-
- /**
- * Return the pixel array descriptor
- *
- * @return pixel array descriptor
- */
- public PixelArray getPixelArray() {
- return _pixarray;
- }
-
- /**
- * Return the blue color data
- *
- * @param RGB packed color data
- * @return blue color data
- */
- public int getBlue(int RGB) {
- return RGB & 0xff;
- }
-
- /**
- * Return the green color data
- *
- * @param RGB packed color data
- * @return green color data
- */
- public int getGreen(int RGB) {
- return (RGB & 0xff00) >> 8;
- }
-
- /**
- * Return the red color data
- *
- * @param RGB packed color data
- * @return red color data
- */
- public int getRed(int RGB) {
- return (RGB & 0xff0000) >> 16;
- }
-
- /**
- * Return the intensity from the color data
- *
- * @param red red color data
- * @param green green color data
- * @param blue blue color data
- * @return intensity
- */
- public double getIntensity(int red, int green, int blue) {
- return Math.sqrt((red * red + green * green + blue * blue) / 3);
- }
-
- /**
- * Return the intensity from the packed color data
- *
- * @param RGB packed color data
- * @return intensity
- */
- public double getIntensity(int RGB) {
- return getIntensity(getRed(RGB), getGreen(RGB), getBlue(RGB));
- }
-
- /**
- * Return the intensity for a given row/col in the pixel array
- * @param row image row
- * @param col image col
- * @return intensity
- */
- public double getIntensity(int row, int col) {
- return getIntensity(getRGB(row, col));
- }
-
- /**
- * Set the packed color data for a pixel
- * @param row image row
- * @param col image column
- * @param RGB packed color data
- */
- public void setRGB(int row, int col, int RGB) {
- _RGB[row][col] = RGB;
- }
-
- /**
- * Set the packed color data for a pixel
- * @param row image row
- * @param col image column
- * @param red red color data
- * @param green green color data
- * @param blue blue color data
- */
- public void setRGB(int row, int col, int red, int green, int blue) {
- setRGB(row, col, makeRGB(red, green, blue));
- }
-
- /**
- * Set the packed color data for a pixel
- *
- * @param pixel pixel number as specified by the pixel array descriptor
- * @param RGB packed color data
- */
- public void setRGB(long pixel, int RGB) {
- setRGB(_pixarray.getRow(pixel), _pixarray.getCol(pixel), RGB);
- }
-
- /**
- * Set the packed color data for a pixel
- *
- * @param pixel pixel number as specified by the pixel array descriptor
- * @param red red color data
- * @param green green color data
- * @param blue blue color data
- */
- public void setRGB(long pixel, int red, int green, int blue) {
- setRGB(pixel, makeRGB(red, green, blue));
- }
-
- /**
- * Return the packed color data for a given element in the image
- *
- * @param row image row
- * @param col image column
- * @return packed color data
- */
- public int getRGB(int row, int col) {
- return _RGB[row][col];
- }
-
- /**
- * Return the packed color data for a pixel
- *
- * @param pixel pixel number as specified by the pixel array descriptor
- * @return packed color data
- */
- public int getRGB(long pixel) {
- return getRGB(_pixarray.getRow(pixel), _pixarray.getCol(pixel));
- }
-
- /**
- * Translate from the BufferedImage color scheme to the one used here. At
- * present, it is believe these schemes are the same based on trial and
- * error techniques. Since it is not entirely clear what format is used
- * for RGB data in a BufferedImage, keep this simple method as a place
- * holder for dealing with possible future complications and for now
- * just mask off the upper 8 bits.
- *
- * @param RGB color data for a BufferedImage pixel
- * @return packed color data
- */
- private int translateBufferedImageRGB(int RGB) {
- // Since the pixel RGB scheme is believed to match the BufferedImage convention,
- // skip decoding the BufferedImage convention
- // int blue = pixel & 0x000000ff;
- // int green = (pixel & 0x0000ff00) >> 8;
- // int red = (pixel & 0x00ff0000) >> 16;
- // return makePixel(red, green, blue);
- return RGB & 0xffffff;
- }
-
- /**
- * Return the packed color given the color components
- *
- * @param red red color data
- * @param green green color data
- * @param blue blue color data
- * @return packed color data
- */
- private int makeRGB(int red, int green, int blue) {
- if (red < 0 || red > 0xff) throw new RuntimeException("Invalid RGB data for red: "+red);
- if (green < 0 || green > 0xff) throw new RuntimeException("Invalid RGB data for green: "+green);
- if (blue < 0 || blue > 0xff) throw new RuntimeException("Invalid RGB data for blue: "+blue);
- return (red << 16) + (green << 8) + red;
- }
-}
CDMS/src/CDMS/Partridge/ImageComparison
diff -N ImageDescriptor.java
--- ImageDescriptor.java 5 Sep 2010 20:20:10 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,180 +0,0 @@
-/*
- * ImageDescriptor.java
- */
-
-package CDMS.Partridge.ImageComparison;
-
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import javax.imageio.ImageIO;
-
-/**
- * Encapsulate the meta-data associated with an image file
- *
- * @author Richard Partrdge
- */
-public class ImageDescriptor {
-
- private String _filename;
- private int _id;
- private double _xc;
- private double _yc;
- private double _dx;
- private double _dy;
- private int _nrow;
- private int _ncol;
-
- /**
- * Fully qualified constructor.
- *
- * @param filename name of image file
- * @param id unique image identifier
- * @param xc x coordinate of image center
- * @param yc y coordinate of image center
- * @param dx x pixel size
- * @param dy y pixel size
- * @param nrow number of rows for image
- * @param ncol number of columns for image
- */
- public ImageDescriptor(String filename, int id, double xc, double yc, double dx,
- double dy, int nrow, int ncol) {
- _filename = filename;
- _id = id;
- _xc = xc;
- _yc = yc;
- _dx = dx;
- _dy = dy;
- _nrow = nrow;
- _ncol = ncol;
- }
-
- /**
- * Constructor that gets image size from the image itself
- *
- * @param filename name of image file
- * @param id unique image identifier
- * @param xc x coordinate of image center
- * @param yc y coordinate of image center
- * @param dx x pixel size
- * @param dy y pixel size
- */
- public ImageDescriptor(String filename, int id, double xc, double yc, double dx, double dy) {
- _filename = filename;
- _id = id;
- _xc = xc;
- _yc = yc;
- _dx = dx;
- _dy = dy;
- BufferedImage bufimage = getBufferedImage();
- _nrow = bufimage.getHeight();
- _ncol = bufimage.getWidth();
- }
-
- /**
- * Return the BufferedImage associated with this image descriptor
- *
- * @return image
- */
- public BufferedImage getBufferedImage() {
- File file = new File(_filename);
- BufferedImage bufimage = null;
- try {
- bufimage = ImageIO.read(file);
- } catch (IOException ex) {
- System.out.println("Image file not found: "+_filename);
- }
- return bufimage;
- }
-
- /**
- * Return the PixelArray associated with this image descriptor
- *
- * @return pixel array descriptor
- */
- public PixelArray getPixelArray() {
- return new PixelArray(_nrow, _ncol, _xc, _yc, _dx, _dy);
- }
-
- /**
- * Return the ImageData associated with this image descriptor
- *
- * @return image
- */
- public ImageData getImageData() {
- return new ImageData(getPixelArray(), getBufferedImage());
- }
-
- /**
- * Return image identifer
- *
- * @return
- */
- public int getIdentifer() {
- return _id;
- }
-
- /**
- * Retrun the x pixel size
- *
- * @return x pixel size
- */
- public double getXSize() {
- return _dx;
- }
-
- /**
- * Return the y pixel size
- *
- * @return y pixel size
- */
- public double getYSize() {
- return _dy;
- }
-
- /**
- * Return the file name containing the image
- *
- * @return image file name
- */
- public String getFilename() {
- return _filename;
- }
-
- /**
- * Return the number of columns for this image
- *
- * @return number of columns
- */
- public int getNCol() {
- return _ncol;
- }
-
- /**
- * Return the number of rows for this image
- *
- * @return number of rows
- */
- public int getNRow() {
- return _nrow;
- }
-
- /**
- * Return the x coordinate of the image center
- *
- * @return x coordinate
- */
- public double getXC() {
- return _xc;
- }
-
- /**
- * Return the y coordinate of the image center
- *
- * @return y coordinate
- */
- public double getYC() {
- return _yc;
- }
-
-}
CDMS/src/CDMS/Partridge/ImageComparison
diff -N PixelArray.java
--- PixelArray.java 6 Sep 2010 20:30:43 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,402 +0,0 @@
-/*
- * PixelArray.java
- */
-
-package CDMS.Partridge.ImageComparison;
-
-import java.awt.image.BufferedImage;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * This class encapsulates a description of a pixel array associated with a physical
- * object. Sufficient information is available to provide convert between a pixel
- * identifier, x/y coordinates, and row/column of the image.
- *
- * The pixel array may have associated with it non-overlapping subarrays. This
- * allows pixel array descriptions to be composed of smaller pixel arrays stitched
- * together to form a much larger pixel array descriptor.
- *
- * @author Richard Partridge
- */
-public class PixelArray {
-
- private int _nrow;
- private int _ncol;
- private double _xc;
- private double _yc;
- private double _dx;
- private double _dy;
- private Map<Integer, PixelArray> _subarraymap;
- private double _eps = 1.e-4; // set tolerance to 0.1 um
-
- /**
- * Fully qualified constructor
- *
- * @param nrow number of rows for this pixel array
- * @param ncol number of columns for this pixel array
- * @param xc x coordinate of the center of the pixel array
- * @param yc y coordinate of the center of the pixel array
- * @param dx x pixel size
- * @param dy y pixel size
- */
- public PixelArray(int nrow, int ncol, double xc, double yc, double dx, double dy) {
- _nrow = nrow;
- _ncol = ncol;
- _xc = xc;
- _yc = yc;
- _dx = dx;
- _dy = dy;
- if (_nrow < 0 || _ncol < 0) throw new RuntimeException("Negative array size - nrow: "+nrow+" ncol: "+ncol);
- if (_dx <= 0. || _dy <= 0.) throw new RuntimeException("Negative pixel size - dx: "+_dx+" dy: "+dy);
- _subarraymap = new HashMap<Integer, PixelArray>();
- }
-
- /**
- * Constructor that uses a Buffered Image to specify the number of row/columns in
- * the pixel array
- *
- * @param bufimage BufferedImage represented by this pixel array descriptor
- * @param xc x coordinate of the center of the pixel array
- * @param yc y coordinate of the center of the pixel array
- * @param dx x pixel size
- * @param dy y pixel size
- */
- public PixelArray(BufferedImage bufimage, double xc, double yc, double dx, double dy) {
- this(bufimage.getHeight(), bufimage.getWidth(), xc, yc, dx, dy);
- }
-
- /**
- * Return the row number for a given pixel
- *
- * @param pixel pixel identifier
- * @return row number
- */
- public int getRow(long pixel) {
- int row = (int) ((pixel >> 32) & 0xffffffffL);
- if (row < 0 || row >= _nrow) throw new RuntimeException("Invalid pixel number"+pixel);
- return row;
- }
-
- /**
- * Return the row number for a given y coordinate
- *
- * @param y y coordinate
- * @return row number
- */
- public int getRow(double y) {
- int ipix = (int) Math.floor((y - _yc) / _dy + _nrow / 2.);
- if (ipix < 0 || ipix >= _nrow) throw new RuntimeException("Row outside pixel array for y = "+y);
- return ipix;
- }
-
- /**
- * Return the column number for a given pixel
- * @param pixel pixel identifier
- * @return column number
- */
- public int getCol(long pixel) {
- int col = (int) (pixel & 0xffffffffL);
- if (col < 0 || col >= _ncol) throw new RuntimeException("Invalid pixel number"+pixel);
- return col;
- }
-
- /**
- * Return the column number for a given x coordinate
- *
- * @param x x coordinate
- * @return column number
- */
- public int getCol(double x) {
- int ipix = (int) Math.floor((x - _xc) / _dx + _ncol / 2.);
- if (ipix < 0 || ipix >= _ncol) throw new RuntimeException("Col outside pixel array for x = "+x);
- return ipix;
- }
-
- /**
- * Return the pixel identifier for a given row and column
- * @param row row number
- * @param col column number
- * @return pixel identifier
- */
- public long getPixel(int row, int col) {
- if (row < 0 || row >= _nrow) throw new RuntimeException("Invalid row number"+row);
- if (col < 0 || col >= _ncol) throw new RuntimeException("Invalid col number"+col);
- long lrow = row;
- long lcol = col;
- return (lrow << 32) + lcol;
- }
-
- /**
- * Return the pixel identifier for a given x,y coordinate
- *
- * @param x x coordinate
- * @param y y coordinate
- * @return pixel identifier
- */
- public long getPixel(double x, double y) {
- return getPixel(getRow(y), getCol(x));
- }
-
- /**
- * Return the number of rows associated with this pixel array
- *
- * @return number of rows
- */
- public int getNRow() {
- return _nrow;
- }
-
- /**
- * Return the number of columns associated with this pixel array
- *
- * @return number of columns
- */
- public int getNCol() {
- return _ncol;
- }
-
- /**
- * Return the x coordinate of a given pixel
- *
- * @param pixel pixel identifier
- * @return x coordinate
- */
- public double getX(long pixel) {
- return _xc + (getCol(pixel) - (_ncol - 1.) / 2.) * _dx;
- }
-
- /**
- * Return the y coordinate of a given pixel
- *
- * @param pixel pixel identifier
- * @return y coordinate
- */
- public double getY(long pixel) {
- return _yc + (getRow(pixel) - (_nrow - 1.) / 2.) * _dy;
- }
-
- /**
- * Return the x coordinate of the center of the pixel array
- *
- * @return x center coordinate
- */
- public double getXC() {
- return _xc;
- }
-
- /**
- * Return the y coordinate of the center of the pixel array
- *
- * @return y center coordinate
- */
- public double getYC() {
- return _yc;
- }
-
- /**
- * Return the width in x of a pixel
- *
- * @return x pixel size
- */
- public double getXSize() {
- return _dx;
- }
-
- /**
- * Return the height in y of a pixel
- *
- * @return y pixel size
- */
- public double getYSize() {
- return _dy;
- }
-
- /**
- * Return the minimum x coordinate for the pixel array
- *
- * @return minimum x coordinate
- */
- public double getXMin() {
- return _xc - 0.5 * _ncol * _dx;
- }
-
- /**
- * Return the maximum x coordinate for the pixel array
- *
- * @return maximum x coordinate
- */
- public double getXMax() {
- return _xc + 0.5 * _ncol * _dx;
- }
-
- /**
- * Return the minimum y coordinate of the pixel array
- *
- * @return minimum y coordinate
- */
- public double getYMin() {
- return _yc - 0.5 * _nrow * _dy;
- }
-
- /**
- * Return the maximum y coordinate of the pixel array
- *
- * @return maximum y coordinate
- */
- public double getYMax() {
- return _yc + 0.5 * _nrow * _dy;
- }
-
- /**
- * Check whether a given x coordinate is within the pixel array
- *
- * @param x x coordinate
- * @return true if inside
- */
- public boolean xInside(double x) {
- return Math.abs(x -_xc) < 0.5 * _ncol * _dx + _eps;
- }
-
- /**
- * Check whether a given y coordinate is within the pixel array
- *
- * @param y y coordinate
- * @return true if inside
- */
- public boolean yInside(double y) {
- return Math.abs(y -_yc) < 0.5 * _nrow * _dy + _eps;
- }
-
- /**
- * Check whether a given x,y coordinate is within the pixel array
- *
- * @param x x coordinate
- * @param y y coordinate
- * @return true if inside
- */
- public boolean Inside(double x, double y) {
- return xInside(x) && yInside(y);
- }
-
- /**
- * Check whether a given pixel identifier describes a pixel within the pixel array
- *
- * @param pixel pixel identifier
- * @return true if inside
- */
- public boolean Inside(long pixel) {
- return Inside(getX(pixel), getY(pixel));
- }
-
- /**
- * Add a subarray to this pixel array. The subarray must be fully contained
- * within the pixel array and not overlap any other subarrays that are present.
- *
- * @param id identifier for this subarray (must be >=0)
- * @param sub subarray
- */
- public void addSubArray(int id, PixelArray sub) {
-
- // Check that we have a positive subarray identifer (negative values will be used to
- // identify error conditions)
- if (id < 0) throw new RuntimeException("Subarray ID must be non-negative - ID: "+id);
-
- // Make sure that the identifier is unique
- if (_subarraymap.containsKey(id)) throw new RuntimeException("Duplicate subarray identifier");
-
- // Make sure subarray is entirely inside this pixel array
- if (!Inside(sub.getXMin(), sub.getYMin()) || !Inside(sub.getXMax(), sub.getYMax()))
- throw new RuntimeException("Subarray is not contained within this pixel array");
-
- // Loop over the other subarrays and make sure that we don't overlap any of them
- for (PixelArray check : _subarraymap.values()) {
- long ll = getPixel(0, 0);
- long lr = getPixel(0, check.getNCol() -1);
- long ul = getPixel(check.getNRow() - 1, 0);
- long ur = getPixel(check.getNRow() - 1, check.getNCol() - 1);
- if (Inside(ll) || Inside(lr) || Inside(ul) || Inside(ur))
- throw new RuntimeException("New subarray overlaps an existing subarray");
- }
-
- // Put the subarray into the map that contains the subarrays and their identifiers
- _subarraymap.put(id, sub);
- }
-
- /**
- * Get the subarray identifier associated with a given x,y position. Returns
- * a value of -1 if there is no subarray containing these coordinates.
- *
- * @param x x coordinate
- * @param y y coordinate
- * @return subarray identifier
- */
- public int getSubArrayID(double x, double y) {
- for (Entry<Integer, PixelArray> sub : _subarraymap.entrySet()) {
- if (sub.getValue().Inside(x, y)) return sub.getKey();
- }
- return -1;
- }
-
- /**
- * Return the subarray descriptor associated with a given x,y position
- *
- * @param x x coordinate
- * @param y y coordinate
- * @return subarray
- */
- public PixelArray getSubArray(double x, double y) {
- int id = getSubArrayID(x, y);
- return _subarraymap.get(id);
- }
-
- /**
- * Return the subarray descriptor for a given ID
- *
- * @param id subarray identifier
- * @return subarray
- */
- public PixelArray getSubArray(int id) {
- return _subarraymap.get(id);
- }
-
- /**
- * Return a list of neighbors to a given pixel
- *
- * @param pixel pixel identifier
- * @return set of neighbor pixels
- */
- public Set<Long> getNeighbors(long pixel) {
- Set<Long> nbrs = new HashSet<Long>();
- int row = getRow(pixel);
- int col = getCol(pixel);
- for (int irow=row-1; irow<=row+1; irow++) {
- if (irow < 0 || irow >= _nrow) continue;
- for (int icol=col-1; icol<=col+1; icol++) {
- if (icol < 0 || icol >= _ncol) continue;
- nbrs.add(getPixel(irow, icol));
- }
- }
- return nbrs;
- }
-
- public boolean equals(PixelArray test) {
- if (_ncol != test.getNCol()) return false;
- if (_nrow != test.getNRow()) return false;
- if (Math.abs(_xc - test.getXC()) > _eps) return false;
- if (Math.abs(_yc - test.getYC()) > _eps) return false;
- if (Math.abs(_dx - test.getXSize()) > _eps / _ncol) return false;
- if (Math.abs(_dy - test.getYSize()) > _eps / _nrow) return false;
- for (Entry<Integer, PixelArray> entry : _subarraymap.entrySet()) {
- int id = entry.getKey();
- PixelArray subarray = entry.getValue();
- PixelArray testsub = test._subarraymap.get(id);
- if (testsub == null) return false;
- if (!subarray.equals(testsub)) return false;
- }
- return true;
- }
-}
CVSspam 0.2.8