Example usage for java.awt.image BufferedImage getRGB

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

Introduction

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

Prototype

public int getRGB(int x, int y) 

Source Link

Document

Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.

Usage

From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java

private static BufferedImage changeColor(BufferedImage image, Color mask, Color replacement) {
    BufferedImage destImage = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = destImage.createGraphics();
    g.drawImage(image, null, 0, 0);/*w  w  w.j  a  va  2s  . c  om*/
    g.dispose();

    for (int i = 0; i < destImage.getWidth(); i++) {
        for (int j = 0; j < destImage.getHeight(); j++) {

            int destRGB = destImage.getRGB(i, j);

            if (matches(mask.getRGB(), destRGB)) {
                int rgbnew = getNewPixelRGB(replacement.getRGB(), destRGB);
                destImage.setRGB(i, j, rgbnew);
            }
        }
    }

    return destImage;
}

From source file:preprocessing.Utils.java

public static BufferedImage removeNoisePoints(BufferedImage img) {
    for (int i = 0; i < img.getWidth(); i++) {
        for (int j = 0; j < img.getHeight(); j++) {
            int negros = 0;
            if (i + 1 < img.getWidth() && img.getRGB(i + 1, j) == -16777216)
                negros++;//from   w w w  .jav  a 2 s. co m
            if (i + 1 < img.getWidth() && j - 1 >= 0 && img.getRGB(i + 1, j - 1) == -16777216)
                negros++;
            if (j - 1 >= 0 && img.getRGB(i, j - 1) == -16777216)
                negros++;
            if (i - 1 >= 0 && j - 1 >= 0 && img.getRGB(i - 1, j - 1) == -16777216)
                negros++;
            if (i - 1 >= 0 && img.getRGB(i - 1, j) == -16777216)
                negros++;
            if (i - 1 >= 0 && j + 1 < img.getHeight() && img.getRGB(i - 1, j + 1) == -16777216)
                negros++;
            if (j + 1 < img.getHeight() && img.getRGB(i, j + 1) == -16777216)
                negros++;
            if (i + 1 < img.getWidth() && j + 1 < img.getHeight() && img.getRGB(i + 1, j + 1) == -16777216)
                negros++;
            if (negros <= 2)
                img.setRGB(i, j, -1);
        }
    }
    return img;
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractRedColor(BufferedImage source) {
    //Extracts the Red 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.getRed();
            values[(i * imageWidth) + j] = value;
        }/*from   w ww .  j  ava 2  s  .co m*/
    }

    return values;
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

public static boolean imgEquals(File imgRef, File img) throws IOException {
    if (isCached(imgRef, img)) {
        return getComparisons(imgRef).get(img).booleanValue();
    } else if (isCached(img, imgRef)) {
        return getComparisons(img).get(imgRef).booleanValue();
    } else {/* w ww.j a  v  a  2  s .  co  m*/
        BufferedImage refBI = ImageIO.read(imgRef);
        BufferedImage imgBi = ImageIO.read(img);

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

        if (refBI.getWidth() == width && refBI.getHeight() == height) {
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    int refIntensity = refBI.getRGB(x, y);
                    int imgIntensity = imgBi.getRGB(x, y);
                    if (refIntensity != imgIntensity) {
                        getComparisons(imgRef).put(img, false);
                        return false;
                    }
                }
            }
        }

        getComparisons(imgRef).put(img, true);
        return true;
    }
}

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;
        }/*  www .j  av  a  2 s  . c om*/
    }

    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;
        }/*from   www .j  a  va 2 s  .  co 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 w  w w .  j  av  a2s  .  co m
    }

    return values;
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(String ip) throws IOException {
    BufferedImage image;
    int width, height;

    File input = new File(ip);
    image = ImageIO.read(input);//from  w  w w. j  av a2s . com
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }

    HSV2File(hsvImage, width, height);

    return hsvImage;
}

From source file:ml.hsv.java

public static hsv[][] img2RGB2HSV(File input) throws IOException {
    BufferedImage image;
    int width, height;

    // File input = new File(ip);
    image = ImageIO.read(input);//from www.j a  v a  2s .  co  m
    width = image.getWidth();
    height = image.getHeight();

    hsv hsvImage[][] = new hsv[height][width];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Color c = new Color(image.getRGB(j, i));
            hsvImage[i][j] = new hsv(c.getRed(), c.getGreen(), c.getBlue());
        }
    }
    // HSV2File(hsvImage,width,height); debugging code removed      
    return hsvImage;
}

From source file:com.smash.revolance.ui.model.helper.ImageHelper.java

/**
 * diff = (img2.rgb(x,y) != img1.rgb(x,y)) ? img1.rgb() : 0
 *
 * @param img1/*www  . j  av  a 2  s .co  m*/
 * @param img2
 * @return
 * @throws IOException
 */
public static BufferedImage diffImg(BufferedImage img1, BufferedImage img2) throws IOException {
    int w = img1.getWidth();
    int h = img1.getHeight();
    int t = img1.getType();

    BufferedImage diff = new BufferedImage(w, h, t);

    if (img1.getWidth() == img2.getWidth() && img1.getHeight() == img2.getHeight()) {
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                int refIntensity = img1.getRGB(x, y);
                int imgIntensity = img2.getRGB(x, y);
                if (refIntensity != imgIntensity) {
                    diff.setRGB(x, y, imgIntensity);
                } else {
                    diff.setRGB(x, y, 0);
                }
            }
        }
    }

    return diff;
}