Figured out, that it wasn't "1", but infact "0". Finished implementation
of getBrightestSpotGrayscale (WARNING ⚠️: untested code). To be done:
Write test cases for all the methods
This commit is contained in:
parent
48512ecb93
commit
1f67f51467
@ -4,8 +4,11 @@ import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChristmasTreeScanning {
|
||||
//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
|
||||
private Point getBrightestSpotGrayscale(BufferedImage grayScaleImage, byte gammaDelta) {
|
||||
int[] imageColors = grayScaleImage.getRGB(0, 0, grayScaleImage.getWidth(), grayScaleImage.getHeight(), null, 0, 0);
|
||||
|
||||
@ -13,9 +16,26 @@ public class ChristmasTreeScanning {
|
||||
imageColors[i] &= 0x0000_00FF; // because the image is grayscale, only one component is needed
|
||||
}
|
||||
|
||||
//TODO
|
||||
int brightestValue = 0;
|
||||
|
||||
Point brightestSpot = new Point(0, 0);
|
||||
for(int i = 0; i < imageColors.length; i++) {
|
||||
if(brightestValue < imageColors[i]) {
|
||||
brightestValue = imageColors[i];
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> brightSpots = new ArrayList<Integer>();
|
||||
|
||||
for(int i = 0; i < imageColors.length; i++) {
|
||||
if(imageColors[i] >= brightestValue - gammaDelta) {
|
||||
brightSpots.add(Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
|
||||
//The following line might be incorrect; TODO double check and write a test
|
||||
Point brightPoints[] = brightSpots.stream().map(s -> new Point(s.intValue() % grayScaleImage.getWidth(), s.intValue() / grayScaleImage.getWidth())).toArray(Point[]::new);
|
||||
|
||||
Point brightestSpot = new PointInterpolator(brightPoints).getCenter();
|
||||
|
||||
return brightestSpot;
|
||||
}
|
||||
@ -68,7 +88,7 @@ public class ChristmasTreeScanning {
|
||||
}
|
||||
|
||||
public Point getBrightestSpot(BufferedImage image) {
|
||||
return getBrightestSpot(image, (byte)1); //TODO is it really 1?
|
||||
return getBrightestSpot(image, (byte)0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,15 +3,21 @@ package com.cringe_studios.christmastreescanning;
|
||||
import java.awt.Point;
|
||||
|
||||
public class PointInterpolator {
|
||||
Point a;
|
||||
Point b;
|
||||
Point points[];
|
||||
|
||||
public PointInterpolator(Point na, Point nb) {
|
||||
a = na;
|
||||
b = nb;
|
||||
public PointInterpolator(Point...na) {
|
||||
points = na;
|
||||
}
|
||||
|
||||
Point getCenter() {
|
||||
return new Point( (a.x + b.x) / 2, (a.y + b.y) / 2);
|
||||
int xSum = 0;
|
||||
int ySum = 0;
|
||||
|
||||
for(int i = 0; i < points.length; i++) {
|
||||
xSum += points[i].x;
|
||||
ySum += points[i].y;
|
||||
}
|
||||
|
||||
return new Point( xSum / 2, ySum / 2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user