Skip to content

Commit 10aff16

Browse files
committed
Use underlying image for drawing certainty and add draw grids
1 parent 5c294ec commit 10aff16

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/test/groovy/net/zomis/machlearn/images/ImagePainter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.*;
44
import java.awt.image.BufferedImage;
55
import java.io.File;
6+
import java.util.Random;
67
import java.util.function.ToDoubleFunction;
78

89
public class ImagePainter {
@@ -16,6 +17,12 @@ public ImagePainter(int width, int height) {
1617
graphics.fillRect(0, 0, width, width);
1718
}
1819

20+
public ImagePainter(BufferedImage image) {
21+
img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
22+
graphics = img.createGraphics();
23+
graphics.drawImage(image, 0, 0, null);
24+
}
25+
1926
public void drawGrayscale(int x, int y, double value) {
2027
int grayscaleValue = (int) (value * 255);
2128
int rgb = 0xff << 24 | grayscaleValue << 16 | grayscaleValue << 8 | grayscaleValue;
@@ -96,4 +103,19 @@ public static ImagePainter[] visualizeNetworks(ImageNetwork network,
96103
return painters;
97104
}
98105

106+
public void drawGrids(ZRect[][] gridLocations) {
107+
Color[] colors = { new Color(1, 0, 0, 0.6f), new Color(0, 1, 0, 0.6f), new Color(0, 0, 1, 0.6f),
108+
new Color(1, 1, 0, 0.6f), new Color(1, 0, 1, 0.6f), new Color(0, 1, 1, 0.6f)};
109+
for (int y = 0; y < gridLocations.length; y++) {
110+
for (int x = 0; x < gridLocations[y].length; x++) {
111+
ZRect rect = gridLocations[y][x];
112+
if (rect == null) {
113+
continue;
114+
}
115+
Color color = colors[(y * 2 + x) % colors.length];
116+
graphics.setColor(color);
117+
graphics.fillRect(rect.left, rect.top, rect.width(), rect.height());
118+
}
119+
}
120+
}
99121
}

src/test/groovy/net/zomis/machlearn/images/MinesweeperScan.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public void scan() {
148148
// also try find separations by scanning lines and finding the line with the lowest delta diff
149149

150150
ZRect[][] gridLocations = findGrid(board.getImage(), rect);
151+
ImagePainter painter = new ImagePainter(board.getImage());
152+
painter.drawGrids(gridLocations);
153+
painter.save("grids");
154+
151155
char[][] gridValues = scanGrid(board.getImage(), gridLocations, board.getExpected());
152156
for (int y = 0; y < gridValues.length; y++) {
153157
for (int x = 0; x < gridValues[y].length; x++) {
@@ -159,7 +163,7 @@ public void scan() {
159163

160164
private char[][] scanGrid(BufferedImage runImage, ZRect[][] gridLocations, String expected) {
161165
char[][] result = new char[gridLocations.length][gridLocations[0].length];
162-
ImagePainter painter = new ImagePainter(runImage.getWidth(), runImage.getHeight());
166+
ImagePainter painter = new ImagePainter(runImage);
163167

164168
// MinesweeperScan.runOnImage(analyze, network, runImage, m -> m.values().stream().mapToDouble(d -> d).max().getAsDouble());
165169
// ImagePainter[] painters = ImagePainter.visualizeNetworks(network, gridLocations[0][0].width(), gridLocations[0][0].height(), runImage,

0 commit comments

Comments
 (0)