/** * Images are resized so as not to exceed the {@link DocumentBuilder#MAX_IMAGE_DIMENSION}, after that * features are extracted using the given localFeatureExtractor. * @param image is the image * @param localFeatureExtractor selected local feature extractor * @return the input localFeatureExtractor */ public LocalFeatureExtractor extractLocalFeatures(BufferedImage image, LocalFeatureExtractor localFeatureExtractor) { assert (image != null); // Scaling image is especially with the correlogram features very important! // All images are scaled to guarantee a certain upper limit for indexing. if (Math.max(image.getHeight(), image.getWidth()) > DocumentBuilder.MAX_IMAGE_DIMENSION) { image = ImageUtils.scaleImage(image, DocumentBuilder.MAX_IMAGE_DIMENSION); } localFeatureExtractor.extract(image); return localFeatureExtractor; }
@Override public void extract(BufferedImage bimg) { bimg = ImageUtils.get8BitRGBImage(bimg); histogram = Apply(bimg); }
private void extractRadiusWithOne(BufferedImage image) { WritableRaster raster = ImageUtils.getGrayscaleImage(image).getRaster();
public static BufferedImage differenceOfGaussians(BufferedImage image) { BufferedImage img1 = getGrayscaleImage(image); BufferedImage img2 = getGrayscaleImage(image); ConvolveOp gaussian1 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 1.0f))); ConvolveOp gaussian2 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 2.0f))); img1 = gaussian1.filter(img1, null); img2 = gaussian2.filter(img2, null); WritableRaster r1 = img1.getRaster(); WritableRaster r2 = img2.getRaster(); int[] tmp1 = new int[3]; int[] tmp2 = new int[3]; for (int x = 0; x < img1.getWidth(); x++) { for (int y = 0; y < img1.getHeight(); y++) { r1.getPixel(x, y, tmp1); r2.getPixel(x, y, tmp2); tmp1[0] = Math.abs(tmp1[0] - tmp2[0]); // System.out.println("tmp1 = " + tmp1[0]); if (tmp1[0] > 5) tmp1[0] = 0; else tmp1[0] = 255; r1.setPixel(x, y, tmp1); } } return img1; }
BufferedImage img = ImageUtils.createWorkingCopy(read); img = ImageUtils.trimWhiteSpace(img); // trims white space img = ImageUtils.scaleImage(img, maxSideLength); // scales image to 512 max sidelength. scaleFactor = (128d / (double) img.getHeight()); img = ImageUtils.scaleImage(img, ((int) (scaleFactor * img.getWidth())), (int) (scaleFactor * img.getHeight()));
public static BufferedImage removeScratches(BufferedImage img) { int thresholdGray = 196; int thresholdCount = 12; BufferedImage result = getGrayscaleImage(img); WritableRaster raster; int[] pCol = new int[img.getHeight()]; ConvolveOp op = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 2.0f))); result = op.filter(result, null); raster = result.getRaster(); if (p[0] < thresholdGray) { // thresholding checkNeighbour(raster, x, y, thresholdGray, thresholdCount, count); if (count[0] < thresholdCount) { p[0] = 255;
int height = 600; image = ImageUtils.scaleImage(image, width, height); image = ImageUtils.get8BitRGBImage(image); BufferedImage bimg = ImageUtils.scaleImage(image, (int) (0.5 * image.getWidth()), (int) (0.5 * image.getHeight())); double[][] smapM = createSmap(bimg, myPMasks.getPmasks(), myPMasks.getMaskWhite()); double[] ThresBigm = filterM(smapM); BufferedImage bimg2 = ImageUtils.scaleImage(bimg, (int) (0.5 * bimg.getWidth()), (int) (0.5 * bimg.getHeight())); double[][] smapS = createSmap(bimg2, myPMasks.getPmasks(), myPMasks.getMaskWhite());
@Override public void extract(BufferedImage bimg) { bimg = ImageUtils.get8BitRGBImage(bimg); histogram[i][j] = 0; WritableRaster grey = ImageUtils.getGrayscaleImage(bimg).getRaster(); WritableRaster raster = bimg.getRaster(); int[] px = new int[3];
/** * Trims the white border around an image. * * @param img * @return a new image, hopefully trimmed. */ public static BufferedImage trimWhiteSpace(BufferedImage img, int whiteThreshold, int startTop, int startRight, int startBottom, int startLeft) { return trimWhiteSpace(img, img, whiteThreshold, startTop, startRight, startBottom, startLeft); }
private void useRandom(BufferedImage image) { listOfFeatures = new LinkedList<SimpleFeature>(); int[] myKeypoint = new int[3]; Random r = new Random(); for (int i = 0; i < samplePoints; i++) { createNextRandomPoint(myKeypoint, image.getWidth(), image.getHeight(), r); globalFeature.extract(ImageUtils.cropImage(image, myKeypoint[0], myKeypoint[1], myKeypoint[2], myKeypoint[2])); listOfFeatures.add(new SimpleFeature(globalFeature.getFeatureVector(), myKeypoint[0], myKeypoint[1], myKeypoint[2], fieldName, featureName, globalFeatureClass)); } }
private static void checkNeighbour(WritableRaster raster, int x, int y, int thresholdGray, int thresholdCount, int[] count) { if (count[0] > thresholdCount) return; int[] pixel = new int[1]; if (x >= raster.getWidth()) return; if (y >= raster.getHeight()) return; raster.getPixel(x, y, pixel); if (pixel[0] < thresholdGray) { count[0] += 1; if (count[0] < thresholdCount) { // checkNeighbour(raster, x, y, thresholdGray, thresholdCount, count); checkNeighbour(raster, x, y + 1, thresholdGray, thresholdCount, count); checkNeighbour(raster, x + 1, y, thresholdGray, thresholdCount, count); checkNeighbour(raster, x + 1, y + 1, thresholdGray, thresholdCount, count); checkNeighbour(raster, x - 1, y + 1, thresholdGray, thresholdCount, count); } } }
public static BufferedImage removeScratches(BufferedImage img) { int thresholdGray = 196; int thresholdCount = 12; BufferedImage result = getGrayscaleImage(img); WritableRaster raster; int[] pCol = new int[img.getHeight()]; ConvolveOp op = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 2.0f))); result = op.filter(result, null); raster = result.getRaster(); if (p[0] < thresholdGray) { // thresholding checkNeighbour(raster, x, y, thresholdGray, thresholdCount, count); if (count[0] < thresholdCount) { p[0] = 255;
int height = 600; image = ImageUtils.scaleImage(image, width, height); image = ImageUtils.get8BitRGBImage(image); BufferedImage bimg = ImageUtils.scaleImage(image, (int) (0.5 * image.getWidth()), (int) (0.5 * image.getHeight())); double[][] smapM = createSmap(bimg, myPMasks.getPmasks(), myPMasks.getMaskWhite()); double[] ThresBigm = filterM(smapM); BufferedImage bimg2 = ImageUtils.scaleImage(bimg, (int) (0.5 * bimg.getWidth()), (int) (0.5 * bimg.getHeight())); double[][] smapS = createSmap(bimg2, myPMasks.getPmasks(), myPMasks.getMaskWhite());
public static BufferedImage differenceOfGaussians(BufferedImage image) { BufferedImage img1 = getGrayscaleImage(image); BufferedImage img2 = getGrayscaleImage(image); ConvolveOp gaussian1 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 1.0f))); ConvolveOp gaussian2 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 2.0f))); img1 = gaussian1.filter(img1, null); img2 = gaussian2.filter(img2, null); WritableRaster r1 = img1.getRaster(); WritableRaster r2 = img2.getRaster(); int[] tmp1 = new int[3]; int[] tmp2 = new int[3]; for (int x = 0; x < img1.getWidth(); x++) { for (int y = 0; y < img1.getHeight(); y++) { r1.getPixel(x, y, tmp1); r2.getPixel(x, y, tmp2); tmp1[0] = Math.abs(tmp1[0] - tmp2[0]); // System.out.println("tmp1 = " + tmp1[0]); if (tmp1[0] > 5) tmp1[0] = 0; else tmp1[0] = 255; r1.setPixel(x, y, tmp1); } } return img1; }
@Override public void extract(BufferedImage bimg) { bimg = ImageUtils.get8BitRGBImage(bimg); histogram[i][j] = 0; WritableRaster grey = ImageUtils.getGrayscaleImage(bimg).getRaster(); WritableRaster raster = bimg.getRaster(); int[] px = new int[3];
/** * Trims the white border around an image. * * @param img * @return a new image, hopefully trimmed. */ public static BufferedImage trimWhiteSpace(BufferedImage img) { return trimWhiteSpace(img, 250, 0, 0, 0, 0); }
private void useRandom(BufferedImage image) { listOfFeatures = new LinkedList<SimpleFeature>(); int[] myKeypoint = new int[3]; Random r = new Random(); for (int i = 0; i < samplePoints; i++) { createNextRandomPoint(myKeypoint, image.getWidth(), image.getHeight(), r); globalFeature.extract(ImageUtils.cropImage(image, myKeypoint[0], myKeypoint[1], myKeypoint[2], myKeypoint[2])); listOfFeatures.add(new SimpleFeature(globalFeature.getFeatureVector(), myKeypoint[0], myKeypoint[1], myKeypoint[2], fieldName, featureName, globalFeatureClass)); } }
private static void checkNeighbour(WritableRaster raster, int x, int y, int thresholdGray, int thresholdCount, int[] count) { if (count[0] > thresholdCount) return; int[] pixel = new int[1]; if (x >= raster.getWidth()) return; if (y >= raster.getHeight()) return; raster.getPixel(x, y, pixel); if (pixel[0] < thresholdGray) { count[0] += 1; if (count[0] < thresholdCount) { // checkNeighbour(raster, x, y, thresholdGray, thresholdCount, count); checkNeighbour(raster, x, y + 1, thresholdGray, thresholdCount, count); checkNeighbour(raster, x + 1, y, thresholdGray, thresholdCount, count); checkNeighbour(raster, x + 1, y + 1, thresholdGray, thresholdCount, count); checkNeighbour(raster, x - 1, y + 1, thresholdGray, thresholdCount, count); } } }
/** * Images are resized so as not to exceed the {@link DocumentBuilder#MAX_IMAGE_DIMENSION}, after that * features are extracted using the given localFeatureExtractor. * @param image is the image * @param localFeatureExtractor selected local feature extractor * @return the input localFeatureExtractor */ public LocalFeatureExtractor extractLocalFeatures(BufferedImage image, LocalFeatureExtractor localFeatureExtractor) { assert (image != null); // Scaling image is especially with the correlogram features very important! // All images are scaled to guarantee a certain upper limit for indexing. if (Math.max(image.getHeight(), image.getWidth()) > DocumentBuilder.MAX_IMAGE_DIMENSION) { image = ImageUtils.scaleImage(image, DocumentBuilder.MAX_IMAGE_DIMENSION); } localFeatureExtractor.extract(image); return localFeatureExtractor; }
private void extractRadiusWithOne(BufferedImage image) { WritableRaster raster = ImageUtils.getGrayscaleImage(image).getRaster();