@Override public void extract(BufferedImage bimg) { BufferedImage gray = grayscale.filter(bimg, null); // contrast enhancement didn't go to well with the wang 1000 data set. // enhanceContrast(gray); BufferedImage small = new BufferedImage(sideLength, sideLength, BufferedImage.TYPE_BYTE_GRAY); double scale = (double) Math.max(gray.getWidth(), gray.getHeight()) / 32d; int w = (int) (gray.getWidth() / scale); int h = (int) (gray.getHeight() / scale); int x = 0, y = 0; if (w < sideLength) x = (sideLength - w) / 2; if (h < sideLength) y = (sideLength - h) / 2; small.getGraphics().fillRect(0, 0, sideLength, sideLength); // small.getGraphics().drawImage(gray, 0, 0, 8, 8, null); small.getGraphics().drawImage(gray, x, y, w, h, null); histogram = new double[sideLength * sideLength]; small.getRaster().getPixels(0, 0, sideLength, sideLength, histogram); for (int i = 0; i < histogram.length; i++) { histogram[i] = Math.floor(histogram[i] / 8d); // quantize colors to 32 steps ... } // histogram = jpgDct(histogram); }
@Override public void extract(BufferedImage bimg) { BufferedImage gray = grayscale.filter(bimg, null); // contrast enhancement didn't go to well with the wang 1000 data set. // enhanceContrast(gray); BufferedImage small = new BufferedImage(sideLength, sideLength, BufferedImage.TYPE_BYTE_GRAY); double scale = (double) Math.max(gray.getWidth(), gray.getHeight()) / 32d; int w = (int) (gray.getWidth() / scale); int h = (int) (gray.getHeight() / scale); int x = 0, y = 0; if (w < sideLength) x = (sideLength - w) / 2; if (h < sideLength) y = (sideLength - h) / 2; small.getGraphics().fillRect(0, 0, sideLength, sideLength); // small.getGraphics().drawImage(gray, 0, 0, 8, 8, null); small.getGraphics().drawImage(gray, x, y, w, h, null); histogram = new double[sideLength * sideLength]; small.getRaster().getPixels(0, 0, sideLength, sideLength, histogram); for (int i = 0; i < histogram.length; i++) { histogram[i] = Math.floor(histogram[i] / 8d); // quantize colors to 32 steps ... } // histogram = jpgDct(histogram); }
/** * Converts an image (RGB, RGBA, ... whatever) to a binary one based on given threshold * * @param image the image to convert. Remains untouched. * @param threshold the threshold in [0,255] * @return a new BufferedImage instance of TYPE_BYTE_GRAY with only 0'S and 255's */ public static BufferedImage thresholdImage(BufferedImage image, int threshold) { BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); result.getGraphics().drawImage(image, 0, 0, null); WritableRaster raster = result.getRaster(); int[] pixels = new int[image.getWidth()]; for (int y = 0; y < image.getHeight(); y++) { raster.getPixels(0, y, image.getWidth(), 1, pixels); for (int i = 0; i < pixels.length; i++) { if (pixels[i] < threshold) pixels[i] = 0; else pixels[i] = 255; } raster.setPixels(0, y, image.getWidth(), 1, pixels); } return result; }
/** * Converts an image (RGB, RGBA, ... whatever) to a binary one based on given threshold * * @param image the image to convert. Remains untouched. * @param threshold the threshold in [0,255] * @return a new BufferedImage instance of TYPE_BYTE_GRAY with only 0'S and 255's */ public static BufferedImage thresholdImage(BufferedImage image, int threshold) { BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); result.getGraphics().drawImage(image, 0, 0, null); WritableRaster raster = result.getRaster(); int[] pixels = new int[image.getWidth()]; for (int y = 0; y < image.getHeight(); y++) { raster.getPixels(0, y, image.getWidth(), 1, pixels); for (int i = 0; i < pixels.length; i++) { if (pixels[i] < threshold) pixels[i] = 0; else pixels[i] = 255; } raster.setPixels(0, y, image.getWidth(), 1, pixels); } return result; }
original.getRaster().getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
original.getRaster().getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
int colorPos; for (int x = 1; x < raster.getWidth() - 1; x++) { raster.getPixels(x, 1, 1, raster.getHeight()-2, px); for (int y = 0; y < raster.getHeight() - 2; y++) { o1 = (double) (px[y*3] - px[y*3+1]) / sq2;
raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) bin += 1; if (pixel[1] >= pixel[4]) bin += 2;
raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) bin += 1; if (pixel[1] >= pixel[4]) bin += 2;
int colorPos; for (int x = 1; x < raster.getWidth() - 1; x++) { raster.getPixels(x, 1, 1, raster.getHeight()-2, px); for (int y = 0; y < raster.getHeight() - 2; y++) { o1 = (double) (px[y*3] - px[y*3+1]) / sq2;
raster.getPixels(x, y, 5, 5, pixel); if (pixel[1] >= pixel[12]) bin += 1; if (pixel[2] >= pixel[12]) bin += 2;
raster.getPixels(x, y, 5, 5, pixel); if (pixel[1] >= pixel[12]) bin += 1; if (pixel[2] >= pixel[12]) bin += 2;
for (int y = 0; y < raster.getHeight() - 2; y++) { Arrays.fill(pattern, 0); raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
for (int y = 0; y < raster.getHeight() - 2; y++) { Arrays.fill(pattern, 0); raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
for (int y = 0; y < raster.getHeight() - 2; y++) { Arrays.fill(pattern, 0); raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
for (int y = 0; y < raster.getHeight() - 2; y++) { Arrays.fill(pattern, 0); raster.getPixels(x, y, 3, 3, pixel); if (pixel[0] >= pixel[4]) pattern[0] = 1; if (pixel[1] >= pixel[4]) pattern[1] = 1;
raster.getPixels(x, 0, 1, raster.getHeight(), pCol); for (int y = 0; y < raster.getHeight(); y++) { double graySum = 0; for (int dx = Math.max(0, x - distance); dx < Math.min(raster.getWidth(), x + distance); dx++) { raster.getPixels(dx, 0, 1, raster.getHeight(), pColD); for (int dy = Math.max(0, y - distance); dy < Math.min(y + distance, raster.getHeight()); dy++) { if (dx != x && dy != y) {
raster.getPixels(x, 0, 1, raster.getHeight(), pCol); for (int y = 0; y < raster.getHeight(); y++) { double graySum = 0; for (int dx = Math.max(0, x - distance); dx < Math.min(raster.getWidth(), x + distance); dx++) { raster.getPixels(dx, 0, 1, raster.getHeight(), pColD); for (int dy = Math.max(0, y - distance); dy < Math.min(y + distance, raster.getHeight()); dy++) { if (dx != x && dy != y) {
boolean white = true; while (white) { raster.getPixels(0, trimTop, raster.getWidth(), 1, pixels); for (int i = 0; i < raster.getWidth(); i++) { if (pixels[i] < thresholdWhite) white = false; raster.getPixels(0, raster.getHeight() - 1 - trimBottom, raster.getWidth(), 1, pixels); for (int i = 0; i < raster.getWidth(); i++) { if (pixels[i] < thresholdWhite) white = false; raster.getPixels(trimLeft, 0, 1, raster.getHeight(), pixels); for (int i = 0; i < raster.getHeight(); i++) { if (pixels[i] < thresholdWhite) white = false; raster.getPixels(raster.getWidth() - 1 - trimRight, 0, 1, raster.getHeight(), pixels); for (int i = 0; i < raster.getHeight(); i++) { if (pixels[i] < thresholdWhite) white = false;
raster.getPixels(x, 0, 1, raster.getHeight(), pCol); for (int y = 0; y < raster.getHeight(); y++) { int[] count = {0};