Added:
trunk/src/wosaic/algorithms/
trunk/src/wosaic/algorithms/AbstractAlgorithm.java (contents, props
changed)
trunk/src/wosaic/algorithms/BruteForceAlgorithm.java (contents, props
changed)
Modified:
trunk/src/wosaic/utilities/Mosaic.java
Log:
Start writing new interface for algorithms
Added: trunk/src/wosaic/algorithms/AbstractAlgorithm.java
==============================================================================
--- (empty file)
+++ trunk/src/wosaic/algorithms/AbstractAlgorithm.java Wed Sep 3 11:50:06
2008
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package wosaic.algorithms;
+
+import wosaic.utilities.*;
+
+/**
+ * Represents the base class for all mosaic matching algorithms.
+ * Each algorithm is responsible for analyzing a pool of images from
+ * a plugin and fitting them appropriately into the mosaic.
+ * @author swegner2
+ */
+public abstract class AbstractAlgorithm {
+ public AbstractAlgorithm(Mosaic mos, int[][][] colorMap) {
+ Mos = mos;
+ ColorMap = colorMap;
+ }
+ abstract public void AddPixel(Pixel pixel);
+
+ protected Mosaic Mos;
+ protected int[][][] ColorMap;
+
+ protected int getMatchScore(Pixel pixel, int r, int c) {
+ int[] avgColors = new int[3];
+ pixel.getAvgImageColor(avgColors);
+ final int rmDiff = Math.abs(avgColors[0] - ColorMap[r][c][0]);
+ final int gmDiff = Math.abs(avgColors[1] - ColorMap[r][c][1]);
+ final int bmDiff = Math.abs(avgColors[2] - ColorMap[r][c][2]);
+
+ // Keep a score that dictates how good a match is
+ // Like in golf, a lower score is better. This is simply
+ // made up of the total difference in each channel, added
+ // together. Other weights can be added in the future.
+ return rmDiff + gmDiff + bmDiff;
+ }
+}
Added: trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
==============================================================================
--- (empty file)
+++ trunk/src/wosaic/algorithms/BruteForceAlgorithm.java Wed Sep 3
11:50:06 2008
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package wosaic.algorithms;
+
+import java.awt.Point;
+import java.util.ArrayList;
+
+import wosaic.utilities.Mosaic;
+import wosaic.utilities.Pixel;
+
+/**
+ * @author swegner2
+ *
+ */
+public class BruteForceAlgorithm extends AbstractAlgorithm {
+
+ public BruteForceAlgorithm(Mosaic mos, int[][][] colorMap) {
+ super(mos, colorMap);
+ }
+
+ @Override
+ public void AddPixel(Pixel pixel) {
+ final int[] avgColors = new int[3];
+ for (int r = 0; r < Mos.getParams().resRows; r++)
+ for (int c = 0; c < Mos.getParams().resCols; c++) {
+
+ pixel.getAvgImageColor(avgColors);
+ final int matchScore = getMatchScore(pixel, r, c);
+
+ if (Mos.getPixelAt(r,c) == null)
+ // Just assign this Pixel to this spot
+ Mos.UpdatePixel(r, c, pixel, matchScore);
+
+ else if (matchScore < Mos.getScoreAt(r,c))
+ Mos.UpdatePixel(r,c, pixel, matchScore);
+ }
+
+ // FIXME: What does this do?
+ notifyAll();
+ }
+
+}
Modified: trunk/src/wosaic/utilities/Mosaic.java
==============================================================================
--- trunk/src/wosaic/utilities/Mosaic.java (original)
+++ trunk/src/wosaic/utilities/Mosaic.java Wed Sep 3 11:50:06 2008
@@ -140,6 +140,10 @@
public synchronized Pixel getPixelAt(final int x, final int y) {
return imageGrid[x][y];
}
+
+ public synchronized int getScoreAt(final int x, final int y) {
+ return scoreGrid[x][y];
+ }
/**
* Initializes a mosaic object. A Mosaic object must be initialized before
@@ -264,5 +268,10 @@
_fire(updatedCoords, srcPixel);
notifyAll();
+ }
+
+ public synchronized void UpdatePixel(int row, int col, final Pixel
newPixel, int score) {
+ imageGrid[row][col] = newPixel;
+ scoreGrid[row][col] = score;
}
}