Made use of Point2D.Double in ImageScanner and PointInterpolator
This commit is contained in:
parent
8f98f3eea6
commit
d322503403
@ -1,16 +1,15 @@
|
||||
package com.cringe_studios.christmastreescanning.scanning;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ImageScanner {
|
||||
public static final byte GAMMA_DELTA_DEFAULT = 0;
|
||||
// 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(), new int[grayScaleImage.getWidth()*grayScaleImage.getHeight()], 0, 0);
|
||||
|
||||
static private Point2D getBrightestSpotGrayscale(BufferedImage grayScaleImage, byte gammaDelta) {
|
||||
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
|
||||
@ -33,11 +32,11 @@ public class ImageScanner {
|
||||
}
|
||||
|
||||
// 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);
|
||||
Point2D brightPoints[] = brightSpots.stream()
|
||||
.map(s -> new Point2D.Double(s.intValue() % grayScaleImage.getWidth(), s.intValue() / grayScaleImage.getWidth()))
|
||||
.toArray(Point2D.Double[]::new);
|
||||
|
||||
Point brightestSpot = new PointInterpolator(brightPoints).getCenter();
|
||||
Point2D brightestSpot = new PointInterpolator(brightPoints).getCenter();
|
||||
|
||||
return brightestSpot;
|
||||
}
|
||||
@ -46,11 +45,11 @@ public class ImageScanner {
|
||||
// pixel included in the search set for the brightest spot
|
||||
// The brightest point Operation is done per color dimension, so you could
|
||||
// provide different images for red, green and blue brightest points
|
||||
static public Point getBrightestSpot(BufferedImage redImage, BufferedImage greenImage, BufferedImage blueImage,
|
||||
static public Point2D getBrightestSpot(BufferedImage redImage, BufferedImage greenImage, BufferedImage blueImage,
|
||||
byte gammaDelta) {
|
||||
Point brightestRedSpot = getBrightestSpotGrayscale(redImage, gammaDelta);
|
||||
Point brightestGreenSpot = getBrightestSpotGrayscale(greenImage, gammaDelta);
|
||||
Point brightestBlueSpot = getBrightestSpotGrayscale(blueImage, gammaDelta);
|
||||
Point2D brightestRedSpot = getBrightestSpotGrayscale(redImage, gammaDelta);
|
||||
Point2D brightestGreenSpot = getBrightestSpotGrayscale(greenImage, gammaDelta);
|
||||
Point2D brightestBlueSpot = getBrightestSpotGrayscale(blueImage, gammaDelta);
|
||||
|
||||
double RGdistance = brightestRedSpot.distanceSq(brightestGreenSpot);
|
||||
double GBdistance = brightestGreenSpot.distanceSq(brightestBlueSpot);
|
||||
@ -71,7 +70,7 @@ public class ImageScanner {
|
||||
return brightestSpot.getCenter();
|
||||
}
|
||||
|
||||
static public Point getBrightestSpot(BufferedImage image, byte gammaDelta) {
|
||||
static public Point2D getBrightestSpot(BufferedImage image, byte gammaDelta) {
|
||||
BufferedImage redImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
|
||||
BufferedImage greenImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
|
||||
BufferedImage blueImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
|
||||
@ -92,7 +91,7 @@ public class ImageScanner {
|
||||
return getBrightestSpot(redImage, greenImage, blueImage, gammaDelta);
|
||||
}
|
||||
|
||||
static public Point getBrightestSpot(BufferedImage image) {
|
||||
static public Point2D getBrightestSpot(BufferedImage image) {
|
||||
return getBrightestSpot(image, GAMMA_DELTA_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
package com.cringe_studios.christmastreescanning.scanning;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class PointInterpolator {
|
||||
Point points[];
|
||||
Point2D points[];
|
||||
|
||||
public PointInterpolator(Point...na) {
|
||||
public PointInterpolator(Point2D...na) {
|
||||
points = na;
|
||||
}
|
||||
|
||||
Point getCenter() {
|
||||
Point2D getCenter() {
|
||||
int xSum = 0;
|
||||
int ySum = 0;
|
||||
|
||||
for(int i = 0; i < points.length; i++) {
|
||||
xSum += points[i].x;
|
||||
ySum += points[i].y;
|
||||
xSum += points[i].getX();
|
||||
ySum += points[i].getY();
|
||||
}
|
||||
|
||||
return new Point( xSum / points.length, ySum / points.length);
|
||||
return new Point2D.Double( xSum / points.length, ySum / points.length);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user