Example usage for java.awt.image BufferedImage getHeight

List of usage examples for java.awt.image BufferedImage getHeight

Introduction

In this page you can find the example usage for java.awt.image BufferedImage getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the BufferedImage .

Usage

From source file:Main.java

public static double meanValue(BufferedImage image) {
    Raster raster = image.getRaster();
    double sum = 0.0;

    for (int y = 0; y < image.getHeight(); ++y) {
        for (int x = 0; x < image.getWidth(); ++x) {
            sum += raster.getSample(x, y, 0);
        }/*w ww  .j a v  a  2s  .c  om*/
    }
    return sum / (image.getWidth() * image.getHeight());
}

From source file:Main.java

/**
 * This method cleans input image by replacing all pixels with RGB values
 * from -3092272 (light gray) to -1 (white) with white pixels and
 * from -3092272 (light gray) to -16777216 (black) with black pixels
 * @param image - input image that will be cleaned
 * @return - cleaned input image as BufferedImage
 *///from w ww  . jav a2 s  . c o  m
public static BufferedImage blackAndLightGrayCleaning(BufferedImage image) {
    for (int j = 0; j < image.getHeight(); j++) {
        for (int i = 0; i < image.getWidth(); i++) {
            if (image.getRGB(i, j) > -3092272) {
                image.setRGB(i, j, -1);
            } else {
                image.setRGB(i, j, -16777216);
            }
        }
    }
    return image;
}

From source file:Main.java

public static BufferedImage getTransparentImage(BufferedImage image, Color transparent) {
    BufferedImage img = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            if (image.getRGB(x, y) != transparent.getRGB()) {
                img.setRGB(x, y, image.getRGB(x, y));
            }//from   ww w .ja va 2s.co m
        }
    }
    g.dispose();
    return img;
}

From source file:Main.java

public static BufferedImage getStrokedImage(BufferedImage bi, Shape shape, int strokeWidth) {
    int w = bi.getWidth();
    int h = bi.getHeight();
    BufferedImage bib = new BufferedImage(w, h, bi.getType());
    Graphics2D g = bib.createGraphics();

    BasicStroke bs = new BasicStroke(strokeWidth);
    g.setStroke(bs);/*from   w  w w  .  j  a  v a2s.  c o  m*/
    Rectangle rect = new Rectangle(0, 0, w, h);
    TexturePaint tp = new TexturePaint(bi, rect);
    g.setPaint(tp);
    g.draw(shape);

    g.dispose();
    return bib;
}

From source file:Main.java

static BufferedImage enlarge(BufferedImage image, int n) {
    int w = image.getWidth() / n;
    int h = image.getHeight() / n;

    BufferedImage shrunkImage = new BufferedImage(w, h, image.getType());

    for (int y = 0; y < h; ++y)
        for (int x = 0; x < w; ++x)
            shrunkImage.setRGB(x, y, image.getRGB(x * n, y * n));

    return shrunkImage;
}

From source file:Main.java

/**
 * This method cleans input image by replacing all pixels with RGB values
 * from RGBcolor input (the input color) to -1 (white) with white pixels and
 * from RGBcolor input (the input color) to -16777216 (black) with black pixels
 * @param image - input image that will be cleaned
 * @param RGBcolor - input RGB value of wanted color as reference for celaning
 * @return - cleaned input image as BufferedImage
 *///from   w ww  . j ava 2 s.  c o m
public static BufferedImage colorCleaning(BufferedImage image, int RGBcolor) {
    for (int j = 0; j < image.getHeight(); j++) {
        for (int i = 0; i < image.getWidth(); i++) {
            if (image.getRGB(i, j) == RGBcolor) {
                image.setRGB(i, j, -16777216);
            } else {
                image.setRGB(i, j, -1);
            }
        }
    }
    return image;
}

From source file:Main.java

public static BufferedImage convert2grey(BufferedImage image) {
    BufferedImage grey = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
    Graphics g = grey.getGraphics();
    g.drawImage(image, 0, 0, null);// ww w  . ja  v  a2  s.c o m
    g.dispose();
    BufferedImage rgb = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
    g = rgb.getGraphics();
    g.drawImage(grey, 0, 0, null);
    g.dispose();
    return rgb;
}

From source file:Main.java

public static int imageDifference(BufferedImage imgA, BufferedImage imgB) {

    int dHeight = Math.abs(imgA.getHeight() - imgB.getHeight());
    int dWidth = Math.abs(imgA.getWidth() - imgB.getWidth());

    int diff = 3 * 255 * dHeight * dWidth;
    for (int y = 0; y < Math.min(imgA.getHeight(), imgB.getHeight()); y++) {
        for (int x = 0; x < Math.min(imgA.getWidth(), imgB.getWidth()); x++) {
            final int colourA = imgA.getRGB(x, y);
            final int colourB = imgB.getRGB(x, y);

            diff += Math.abs((int) ((colourA & 0x00ff0000) >> 16) - (int) ((colourB & 0x00ff0000) >> 16));
            diff += Math.abs((int) ((colourA & 0x0000ff00) >> 8) - (int) ((colourB & 0x0000ff00) >> 8));
            diff += Math.abs((int) (colourA & 0x000000ff) - (int) (colourB & 0x000000ff));
        }/*from   ww  w  .  java2s  .  com*/
    }

    return diff;
}

From source file:Main.java

public static BufferedImage replaceColor(BufferedImage src, int sourceRGB, int replaceRGB) {

    for (int y = 0; y < src.getHeight(); y++) {
        for (int x = 0; x < src.getWidth(); x++) {

            int rawRGB = src.getRGB(x, y);
            int rgb = rawRGB & 0xffffff;
            int alpha = rawRGB & 0xff000000;

            if (rgb == sourceRGB) {
                src.setRGB(x, y, alpha | replaceRGB);
            }/*w  ww  .j a  v  a2s  . co  m*/
        }
    }

    return src;
}

From source file:Main.java

/**
 * This method reads the input image from the input from
 * start pixel height (y1) until it reads the first next row
 * where all pixel are white by height and return that value
 * @param Img - input image that will be read
 * @param y1 - input start height pixel of image
 * @return - returns the value of height when conditions are true
 *//*from  w  w w . ja v  a  2  s  . c  o m*/
private static int trimLockdown(BufferedImage Img, int y1) {

    for (int j = y1 + 1; j < Img.getHeight(); j++) {
        int counterWhite = 0;
        for (int i = 0; i < Img.getWidth(); i++) {
            if (Img.getRGB(i, j) == -1) {
                counterWhite++;
            }
        }
        if (counterWhite == Img.getWidth()) {
            //this is a chek for dots over the letters i and j
            //so they wont be missread as dots
            if (j > (Img.getHeight() / 2)) {
                return j;
            }
        }
        if (j == Img.getHeight() - 1) {
            return j + 1;
        }
    }
    return 0;
}