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:net.cloudkit.relaxation.CaptchaTest.java

public static BufferedImage removeBlank(BufferedImage img, int whiteThreshold, int white) throws Exception {
    final int width = img.getWidth();
    final int height = img.getHeight();
    int start = 0;
    int end = 0;/*from   ww w  . ja v a 2s .  c om*/
    Label1: for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (isWhite(img.getRGB(x, y), whiteThreshold) == white) {
                start = y;
                break Label1;
            }
        }
    }
    Label2: for (int y = height - 1; y >= 0; --y) {
        for (int x = 0; x < width; ++x) {
            if (isWhite(img.getRGB(x, y), whiteThreshold) == white) {
                end = y;
                break Label2;
            }
        }
    }
    return img.getSubimage(0, start, width, end - start + 1);
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractBlueColor(BufferedImage source) {
    //Extracts the Blue value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getBlue();
            values[(i * imageWidth) + j] = value;
        }//from   www. j a  v a 2  s.  com
    }

    return values;
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractAlphaValue(BufferedImage source) {
    //Extracts the Alpha value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getAlpha();
            values[(i * imageWidth) + j] = value;
        }/*ww  w  .  java 2  s .c o  m*/
    }

    return values;
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractGreenColor(BufferedImage source) {
    //Extracts the Green value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getGreen();
            values[(i * imageWidth) + j] = value;
        }//from   www.ja  v a2s .co m
    }

    return values;
}

From source file:de.ppi.selenium.util.ScreenshotUtils.java

/**
 * Calculate how similar the 2 immages are.
 *
 * @param var picture1//from  w  w w .j a  v a  2  s  . c om
 * @param cont picture2
 * @return a value between 0 and 1.
 */
private static double similarity(BufferedImage var, BufferedImage cont) {

    final int scale = 3;
    double[] varArr = new double[var.getWidth() * var.getHeight() * scale];
    double[] contArr = new double[cont.getWidth() * cont.getHeight() * scale];

    if (varArr.length != contArr.length) {
        throw new IllegalStateException("The pictures are different sizes!");
    }

    // unroll pixels
    for (int i = 0; i < var.getHeight(); i++) {
        for (int j = 0; j < var.getWidth(); j++) {
            varArr[i * var.getWidth() + j + 0] = new Color(var.getRGB(j, i)).getRed();
            contArr[i * cont.getWidth() + j + 0] = new Color(cont.getRGB(j, i)).getRed();
            varArr[i * var.getWidth() + j + 1] = new Color(var.getRGB(j, i)).getGreen();
            contArr[i * cont.getWidth() + j + 1] = new Color(cont.getRGB(j, i)).getGreen();
            varArr[i * var.getWidth() + j + 2] = new Color(var.getRGB(j, i)).getBlue();
            contArr[i * cont.getWidth() + j + 2] = new Color(cont.getRGB(j, i)).getBlue();
        }
    }

    double mins = 0;
    double maxs = 0;
    for (int i = 0; i != varArr.length; i++) {
        if (varArr[i] > contArr[i]) {
            mins += contArr[i];
            maxs += varArr[i];
        } else {
            mins += varArr[i];
            maxs += contArr[i];
        }
    }
    return mins / maxs;
}

From source file:com.thalespf.dip.DeblurringTest.java

private static void deblurTest() throws IOException {
    String imagePath = "image_blurred.png";
    IImageIO imageIO = ImageIODesktop.createImageIO(imagePath);
    Object imageObject = imageIO.getImageObject();
    if (imageObject == null || !(imageObject instanceof BufferedImage)) {
        throw new IllegalStateException("Nao foi possivel criar a imagem.");
    }//from   w w w . j  ava 2  s.  c o  m

    BufferedImage bufferedImage = (BufferedImage) imageObject;
    WritableRaster raster = bufferedImage.getRaster();

    int width = bufferedImage.getWidth();
    int height = bufferedImage.getHeight();

    double[] fft = new double[2 * width * height];
    FFTForwardInverseTest.fftForward(raster, width, height, fft);

    Complex[] complexImage = new Complex[width * height];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {

            Complex c = new Complex(fft[2 * (x + y * width)], fft[2 * (x + y * width) + 1]);
            complexImage[x + y * width] = c;

        }
    }

    normalizeToMaxAbsValue(complexImage, width, height, 1);

    double[] degradation = new double[2 * width * height];
    //motionBlur (funcao de transferencia)
    Complex[] complexPsf = motionBlur(degradation, width, height);

    normalizeToMaxAbsValue(complexPsf, width, height, 1);

    //deconvolve data
    double[] convoluted = new double[2 * width * height];
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Complex complexImg = complexImage[x + y * width];

            Complex complexDeg = complexPsf[x + y * width];

            Complex m = deconvolutionByWiener(complexImg, complexDeg);

            convoluted[2 * (x + y * width)] = m.getReal();
            convoluted[2 * (x + y * width) + 1] = m.getImaginary();
        }
    }

    double[] imageResult = new double[width * height];
    FFTForwardInverseTest.fftInverse(convoluted, imageResult, width, height);

    int[] image = new int[imageResult.length];
    Expansion.globalExpansion2(imageResult, image, width, height);

    ImageIODesktop imageIODesktop = new ImageIODesktop();
    imageIODesktop.savePixels(image, width, height, null, "image_deblurred");
}

From source file:com.thalespf.dip.DeblurringTest.java

private static void blurTest() throws IOException {
    String imagePath = "image.jpg";
    IImageIO imageIO = ImageIODesktop.createImageIO(imagePath);
    Object imageObject = imageIO.getImageObject();
    if (imageObject == null || !(imageObject instanceof BufferedImage)) {
        throw new IllegalStateException("Nao foi possivel criar a imagem.");
    }/*from  ww w  .  jav a  2 s.com*/

    BufferedImage bufferedImage = (BufferedImage) imageObject;
    WritableRaster raster = bufferedImage.getRaster();

    int width = bufferedImage.getWidth();
    int height = bufferedImage.getHeight();

    double[] fft = new double[2 * width * height];
    FFTForwardInverseTest.fftForward(raster, width, height, fft);

    Complex[] ci = new Complex[width * height];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {

            Complex c = new Complex(fft[2 * (x + y * width)], fft[2 * (x + y * width) + 1]);
            ci[x + y * width] = c;

        }
    }

    normalizeToMaxAbsValue(ci, width, height, 1);

    double[] degradation = new double[2 * width * height];
    //motionBlur (funcao de transferencia)
    Complex[] complexPsf = motionBlur(degradation, width, height);

    normalizeToMaxAbsValue(complexPsf, width, height, 1);

    //convolve data
    double[] convoluted = new double[2 * width * height];
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double realImg = fft[2 * (x + y * width)];
            double imgImg = fft[2 * (x + y * width) + 1];
            Complex complexImage = new Complex(realImg, imgImg);

            double realDeg = degradation[2 * (x + y * width)];
            double imgDeg = degradation[2 * (x + y * width) + 1];
            Complex complexDeg = new Complex(realDeg, imgDeg);

            Complex m = complexImage.multiply(complexDeg);
            convoluted[2 * (x + y * width)] = m.getReal();
            convoluted[2 * (x + y * width) + 1] = m.getImaginary();
        }
    }

    double[] imageResult = new double[width * height];
    FFTForwardInverseTest.fftInverse(convoluted, imageResult, width, height);

    int[] image = new int[imageResult.length];
    Expansion.globalExpansion2(imageResult, image, width, height);

    ImageIODesktop imageIODesktop = new ImageIODesktop();
    imageIODesktop.savePixels(image, width, height, null, "image_blurred");
}

From source file:lucee.runtime.img.ImageUtil.java

public static BufferedImage createBufferedImage(BufferedImage image) {
    return createBufferedImage(image, image.getWidth(), image.getHeight());
}

From source file:com.seleniumtests.util.imaging.ImageProcessor.java

/**
 * Agregate 2 pictures/*from   ww w .j a v a  2s. co  m*/
 * @param imgf1         first picture to agregate
 * @param imgf2         seconde picture to aggregate
 * @param img2PosX      X coord where second picture will be but, relative to first one 
 * @param img2PosY      Y coord where second picture will be but, relative to first one 
 * @return            the complete picture
 */
public static BufferedImage concat(BufferedImage img1, BufferedImage img2, Integer img2PosX, Integer img2PosY) {

    if (img2PosX < 0 || img2PosY < 0) {
        throw new IllegalArgumentException("relative position must be > 0");
    }

    Integer finalWidth = Math.max(img2.getWidth() + img2PosX, img1.getWidth());
    Integer finalHeight = Math.max(img2.getHeight() + img2PosY, img1.getHeight());

    BufferedImage img = new BufferedImage(finalWidth, finalHeight, BufferedImage.TYPE_INT_RGB);

    img.createGraphics().drawImage(img1, 0, 0, null);
    img.createGraphics().drawImage(img2, img2PosX, img2PosY, null);

    return img;
}

From source file:com.opendesign.utils.ThumbnailManager.java

/**
 * ?? ?   //  ww  w.j  a v a  2  s  . co  m
 * ?  width ?  resize ?.
 * @param width
 * @param imageFile
 * @param suffix
 * @throws Exception
 */
private static void resizeNSaveThumbnail(double width, File imageFile, String suffix) throws Exception {

    BufferedImage originalImage = ImageIO.read(imageFile);
    double originalWidth = originalImage.getWidth();
    double originalHeight = originalImage.getHeight();

    double resizableWidth = originalWidth;
    double resizableHeight = originalHeight;

    String extension = imageFile.getName().substring(imageFile.getName().indexOf(".") + 1);
    String fileName = imageFile.getName().substring(0, imageFile.getName().indexOf("."));
    String target = imageFile.getAbsolutePath();
    target = target.substring(0, target.lastIndexOf(File.separator) + 1) + fileName + suffix + "." + extension;

    if (originalWidth > width) {
        resizableWidth = width;
        double ratio = (double) width / (double) originalImage.getWidth();
        resizableHeight = originalImage.getHeight() * ratio;

        Thumbnails.of(originalImage).size((int) resizableWidth, (int) resizableHeight).outputFormat(extension)
                .toFile(target);
    } else {
        CmnUtil.fileCopy(imageFile.getAbsolutePath(), target);
    }

}