[wosaic commit] r342 - Modified brute force to check its neighbors for the same pixel before placing a pixel...

8 views
Skip to first unread message

codesite...@google.com

unread,
Apr 13, 2009, 12:39:23 AM4/13/09
to wosaic...@googlegroups.com
Author: csvenss2
Date: Sun Apr 12 21:29:24 2009
New Revision: 342

Modified:
trunk/src/wosaic/WosaicUI.java
trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
trunk/src/wosaic/utilities/Mosaic.java
trunk/src/wosaic/utilities/Pixel.java

Log:
Modified brute force to check its neighbors for the same pixel before
placing a pixel...

Modified: trunk/src/wosaic/WosaicUI.java
==============================================================================
--- trunk/src/wosaic/WosaicUI.java (original)
+++ trunk/src/wosaic/WosaicUI.java Sun Apr 12 21:29:24 2009
@@ -363,7 +363,6 @@
* generated, and then update the UI.
*/
protected void CancelGeneration() {
- // TODO: Write code for the comments below
// Prompt the user to make sure the process should be
// cancelled.
// Send interrupts to the controller
@@ -374,6 +373,17 @@

ControllerThread.interrupt();
CancelButton.setEnabled(false);
+ GenerateMosaicButton.setEnabled(true);
+ SaveButton.setEnabled(true);
+ BrowseButton.setEnabled(true);
+
+ InputImageText.setEnabled(true);
+ MosaicResolutionText.setEnabled(true);
+ SearchQueryText.setEnabled(true);
+
+ TabbedPane.setEnabledAt(TabbedPane.indexOfComponent(AdvancedOptionsTab),
true);
+
+
StatusUI.setStatus("Mosaic Cancelled!");
StatusUI.setIndeterminate(false);
StatusUI.setProgress(0);

Modified: trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
==============================================================================
--- trunk/src/wosaic/algorithms/BruteForceAlgorithm.java (original)
+++ trunk/src/wosaic/algorithms/BruteForceAlgorithm.java Sun Apr 12
21:29:24 2009
@@ -10,6 +10,7 @@

import wosaic.utilities.Mosaic;
import wosaic.utilities.Pixel;
+import wosaic.utilities.Parameters;

/**
* Simple "brute force" algorithm. Each time we receive a new pixel, Check
each
@@ -74,8 +75,21 @@
// 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);
+ else if (matchScore < Mos.getScoreAt(r, c)) {
+ Pixel[][] imageGrid = Mos.getPixelArr();
+ Parameters params = Mos.getParams();
+
+ // Check neighbors
+ if (r-1 >= 0 && r+1 < params.resRows && c-1 >=0 && c+1
< params.resCols &&
+ imageGrid[r-1][c] != pixel &&
imageGrid[r-1][c+1] != pixel &&
+ imageGrid[r-1][c-1] != pixel &&
imageGrid[r+1][c] != pixel &&
+ imageGrid[r][c+1] != pixel && imageGrid[r][c-1] !=
pixel &&
+ imageGrid[r+1][c-1] != pixel &&
imageGrid[r+1][c+1] != pixel) {
+
+ Mos.UpdatePixel(r, c, pixel, matchScore);
+ }
+
+ }
}
}

@@ -118,7 +132,6 @@
}
}

- @Override
public void run() {
System.err.println("Algorithm thread running");

Modified: trunk/src/wosaic/utilities/Mosaic.java
==============================================================================
--- trunk/src/wosaic/utilities/Mosaic.java (original)
+++ trunk/src/wosaic/utilities/Mosaic.java Sun Apr 12 21:29:24 2009
@@ -243,7 +243,7 @@
final ArrayList<Point> updatedCoords = new ArrayList<Point>();

final int[] avgColors = new int[3];
- for (int r = 0; r < params.resRows; r++)
+ for (int r = 0; r < params.resRows; r++) {
for (int c = 0; c < params.resCols; c++) {

srcPixel.getAvgImageColor(avgColors);
@@ -259,22 +259,31 @@
final int matchScore = (int) Math.sqrt((Math.pow(rmDiff, 2.0) +
Math.pow(gmDiff, 2.0) + Math.pow(bmDiff, 2.0)));

if (imageGrid[r][c] != null) {
-
if (matchScore < scoreGrid[r][c]) {
- imageGrid[r][c] = srcPixel;
- scoreGrid[r][c] = matchScore;
- updatedCoords.add(new Point(r, c));
+ // Check neighbors
+ if (r-1 >= 0 && r+1 < params.resRows && c-1 >=0 &&
c+1 < params.resCols &&
+ imageGrid[r-1][c] != srcPixel &&
imageGrid[r-1][c+1] != srcPixel &&
+ imageGrid[r-1][c-1] != srcPixel &&
imageGrid[r+1][c] != srcPixel &&
+ imageGrid[r][c+1] != srcPixel &&
imageGrid[r][c-1] != srcPixel &&
+ imageGrid[r+1][c-1] != srcPixel &&
imageGrid[r+1][c+1] != srcPixel) {
+
+ imageGrid[r][c] = srcPixel;
+ scoreGrid[r][c] = matchScore;
+ srcPixel.numTimes++;
+ updatedCoords.add(new Point(r, c));
+ }
}

} else {
// Just assign this Pixel to this spot
imageGrid[r][c] = srcPixel;
- scoreGrid[r][c] = matchScore;

// Send an update notification
updatedCoords.add(new Point(r, c));
}
}
+ }
+
if (updatedCoords.size() != 0) _fire(updatedCoords, srcPixel);

notifyAll();
@@ -292,6 +301,7 @@
final Pixel newPixel, int score) {
imageGrid[row][col] = newPixel;
scoreGrid[row][col] = score;
+ newPixel.numTimes++;

// Fire an update
ArrayList<Point> coords = new ArrayList<Point>(1);

Modified: trunk/src/wosaic/utilities/Pixel.java
==============================================================================
--- trunk/src/wosaic/utilities/Pixel.java (original)
+++ trunk/src/wosaic/utilities/Pixel.java Sun Apr 12 21:29:24 2009
@@ -44,6 +44,8 @@
*/
public int width;

+ public int numTimes;
+
/**
* Creates a Pixel object from a BufferedImage
*

Scott Wegner

unread,
Apr 13, 2009, 12:09:55 PM4/13/09
to wosaic...@googlegroups.com
Hey Carl,

Are you starting up work again on Wosaic?

Scott

Carl-Erik Svensson

unread,
Apr 13, 2009, 2:35:45 PM4/13/09
to wosaic...@googlegroups.com
Well, I wanted to make a mosaic for an art project, so I used our program but I was frustrated with all the repeated images.  I made a couple quick changes just to check a pixel's neighbors and not put the same image in any of its 8 surrounding pixels.  My change isn't 100% correct because pictures still end up next to each other, but it does a much better job of making it look random (and the quality and higher resolutions does not degrade).  The result is in my attachment... before both the top and bottom part contained large regions of the same image.

I got pretty excited about this simple change so I figure I'd add it into the repo.  Still haven't taken the time to install the C++ version but there's so many more little things to add I feel like just adding them!  Only problem is time... maybe post graduation...

--
Carl
CupcakeMosaicMedium.png
Reply all
Reply to author
Forward
0 new messages