added generating of images with coordinates given by getBrightestSpot

This commit is contained in:
rgrebner 2023-11-20 14:28:42 +01:00
parent 2fd7d5ed2b
commit 8f98f3eea6
2 changed files with 36 additions and 1 deletions

View File

@ -10,7 +10,7 @@ public class ImageScanner {
// TODO maybe use Point2D.Double as return type, so the Points don't have to be
// converted to Points2D later down the pipeline during the normalization step
static private Point getBrightestSpotGrayscale(BufferedImage grayScaleImage, byte gammaDelta) {
int[] imageColors = grayScaleImage.getRGB(0, 0, grayScaleImage.getWidth(), grayScaleImage.getHeight(), null, 0, 0);
int[] imageColors = grayScaleImage.getRGB(0, 0, grayScaleImage.getWidth(), grayScaleImage.getHeight(), new int[grayScaleImage.getWidth()*grayScaleImage.getHeight()], 0, 0);
for (int i = 0; i < imageColors.length; i++) {
imageColors[i] &= 0x0000_00FF; // because the image is grayscale, only one component is needed

View File

@ -1,13 +1,48 @@
package com.cringe_studios.cristmastreescanning;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.imageio.ImageIO;
import org.junit.jupiter.api.Test;
import com.cringe_studios.christmastreescanning.scanning.ImageScanner;
public class ExampleTest {
@Test
public void testSus() {
assertEquals(1 + 1, 2);
}
@Test
public void generateVisualTestImagees() {
Path results;
try {
results = Files.createTempDirectory("testResult");
for(int i = 0; i < 100; i++) {
try {
BufferedImage image = ImageIO.read(ExampleTest.class.getResourceAsStream("/0_" + i + ".png"));
Point p = ImageScanner.getBrightestSpot(image);
for(int j = -2; j < 2; j++) {
for(int k = -2; k < 2; k++) {
if(p.x + j > 0 && p.x + j < image.getWidth() && p.y + k > 0 && p.y + k < image.getHeight()) image.setRGB(p.x + j, p.y + k, Color.red.getRGB());
}
}
ImageIO.write(image, "png", Files.newOutputStream(results.resolve(String.valueOf(i) + ".png")));
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}