List of usage examples for java.awt.image BufferedImage getRGB
public int getRGB(int x, int y)
From source file:de._13ducks.cor.graphics.GraphicsComponent.java
public static BufferedImage grayScale(BufferedImage im) { // Verwandelt ein Bild ein eine Grayscale-Version, behlt aber die Transparenz BufferedImage grayImage = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < im.getWidth(); x++) { for (int y = 0; y < im.getHeight(); y++) { int argb = im.getRGB(x, y); int a = (argb >> 24) & 0xff; int r = (argb >> 16) & 0xff; int g = (argb >> 8) & 0xff; int b = (argb) & 0xff; int l = (int) (.299 * r + .587 * g + .114 * b); //luminance grayImage.setRGB(x, y, (a << 24) + (l << 16) + (l << 8) + l); }//from www . ja v a 2 s . c o m } return grayImage; }
From source file:net.rptools.lib.image.ImageUtil.java
public static BufferedImage createOutline(BufferedImage sourceImage, Color color) { if (sourceImage == null) { return null; }/* w ww . ja va2s. c o m*/ BufferedImage image = new BufferedImage(sourceImage.getWidth() + 2, sourceImage.getHeight() + 2, Transparency.BITMASK); for (int row = 0; row < image.getHeight(); row++) { for (int col = 0; col < image.getWidth(); col++) { int sourceX = col - 1; int sourceY = row - 1; // Pixel under current location if (sourceX >= 0 && sourceY >= 0 && sourceX <= sourceImage.getWidth() - 1 && sourceY <= sourceImage.getHeight() - 1) { int sourcePixel = sourceImage.getRGB(sourceX, sourceY); if (sourcePixel >> 24 != 0) { // Not an empty pixel, don't overwrite it continue; } } for (int i = 0; i < outlineNeighborMap.length; i++) { int[] neighbor = outlineNeighborMap[i]; int x = sourceX + neighbor[0]; int y = sourceY + neighbor[1]; if (x >= 0 && y >= 0 && x <= sourceImage.getWidth() - 1 && y <= sourceImage.getHeight() - 1) { if ((sourceImage.getRGB(x, y) >> 24) != 0) { image.setRGB(col, row, color.getRGB()); break; } } } } } return image; }
From source file:it.units.malelab.ege.util.DUMapper.java
private static void modifyMap(String fileName, float bins) throws IOException { Color[][] colorMap = new Color[3][]; colorMap[0] = new Color[] { fromCode("000000"), fromCode("b36600"), fromCode("f3b300") }; colorMap[1] = new Color[] { fromCode("376387"), fromCode("b3b3b3"), fromCode("f3e6b3") }; colorMap[2] = new Color[] { fromCode("509dc2"), fromCode("b4d3e1"), fromCode("f3f3f3") }; BufferedImage inImage = ImageIO.read(new File(fileName)); BufferedImage outRGDImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(), BufferedImage.TYPE_INT_ARGB); BufferedImage outCMImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < inImage.getWidth(); x++) { for (int y = 0; y < inImage.getHeight(); y++) { Color inColor = new Color(inImage.getRGB(x, y)); Color outColor = new Color( Math.min((float) Math.floor((float) inColor.getRed() / 255f * bins) / (bins - 1), 1f), Math.min((float) Math.floor((float) inColor.getGreen() / 255f * bins) / (bins - 1), 1f), 0); outRGDImage.setRGB(x, y, outColor.getRGB()); int cmRIndex = (int) Math.min((int) Math.floor((float) inColor.getRed() / 255f * 3), 2); int cmGIndex = (int) Math.min((int) Math.floor((float) inColor.getGreen() / 255f * 3), 2); outColor = colorMap[cmRIndex][cmGIndex]; outCMImage.setRGB(x, y, outColor.getRGB()); }// w w w . j a va 2 s.c o m } ImageIO.write(outRGDImage, "PNG", new File(fileName.replace(".png", String.format(".rgbdisc%d.png", (int) bins)))); ImageIO.write(outCMImage, "PNG", new File(fileName.replace(".png", ".cm.png"))); }
From source file:com.t3.image.ImageUtil.java
public static BufferedImage createOutline(BufferedImage sourceImage, Color color) { if (sourceImage == null) { return null; }/*from ww w.j ava 2 s . c o m*/ BufferedImage image = new BufferedImage(sourceImage.getWidth() + 2, sourceImage.getHeight() + 2, Transparency.BITMASK); for (int row = 0; row < image.getHeight(); row++) { for (int col = 0; col < image.getWidth(); col++) { int sourceX = col - 1; int sourceY = row - 1; // Pixel under current location if (sourceX >= 0 && sourceY >= 0 && sourceX <= sourceImage.getWidth() - 1 && sourceY <= sourceImage.getHeight() - 1) { int sourcePixel = sourceImage.getRGB(sourceX, sourceY); if (sourcePixel >> 24 != 0) { // Not an empty pixel, don't overwrite it continue; } } for (int i = 0; i < outlineNeighborMap.length; i++) { int[] neighbor = outlineNeighborMap[i]; int x = sourceX + neighbor[0]; int y = sourceY + neighbor[1]; if (x >= 0 && y >= 0 && x <= sourceImage.getWidth() - 1 && y <= sourceImage.getHeight() - 1) { if ((sourceImage.getRGB(x, y) >> 24) != 0) { image.setRGB(col, row, color.getRGB()); break; } } } } } return image; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float[][][] getImageDifference(BufferedImage image1, BufferedImage image2) { Color tmpColor1, tmpColor2;//from w w w .j av a 2 s .co m int width = image1.getWidth(); int height = image1.getHeight(); float[][][] outputMap = new float[3][width][height]; for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < height; jj++) { tmpColor1 = new Color(image1.getRGB(ii, jj)); tmpColor2 = new Color(image2.getRGB(ii, jj)); outputMap[0][ii][jj] = (float) (tmpColor1.getRed() - tmpColor2.getRed()) * (tmpColor1.getRed() - tmpColor2.getRed()); outputMap[1][ii][jj] = (float) (tmpColor1.getGreen() - tmpColor2.getGreen()) * (tmpColor1.getGreen() - tmpColor2.getGreen()); outputMap[2][ii][jj] = (float) (tmpColor1.getBlue() - tmpColor2.getBlue()) * (tmpColor1.getBlue() - tmpColor2.getBlue()); } } return outputMap; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static double[][][] getImageDifferenceD(BufferedImage image1, BufferedImage image2) { Color tmpColor1, tmpColor2;/* www .ja v a 2 s . c o m*/ int width = image1.getWidth(); int height = image1.getHeight(); double red_temp, green_temp, blue_temp; double[][][] outputMap = new double[3][width][height]; for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < height; jj++) { tmpColor1 = new Color(image1.getRGB(ii, jj)); tmpColor2 = new Color(image2.getRGB(ii, jj)); red_temp = tmpColor1.getRed() - tmpColor2.getRed(); green_temp = tmpColor1.getGreen() - tmpColor2.getGreen(); blue_temp = tmpColor1.getBlue() - tmpColor2.getBlue(); outputMap[0][ii][jj] = (double) (red_temp) * (red_temp); outputMap[1][ii][jj] = (double) (green_temp) * (green_temp); outputMap[2][ii][jj] = (double) (blue_temp) * (blue_temp); } } return outputMap; }
From source file:pdi.HistogramaRGB.java
public int[] pegaPixels(File file) { BufferedImage img = pegaImagem(); int[] rgb = new int[w * h]; for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) { rgb[i * j] = img.getRGB(i, j); }//from w w w . jav a2s . c om for (int i = 0; i < rgb.length; i++) { Color c = new Color(rgb[i]); System.out.println("Vermelho: " + c.getRed()); } for (int i = 0; i < rgb.length; i++) { Color c = new Color(rgb[i]); System.out.println("Vermelho: " + c.getGreen()); } for (int i = 0; i < rgb.length; i++) { Color c = new Color(rgb[i]); System.out.println("Vermelho: " + c.getBlue()); } return rgb; }
From source file:DBScan.java
private double minDistance(int x, int y, BufferedImage img1, BufferedImage img2) { if (!(x < img1.getWidth() && y < img1.getHeight())) return 0; int colour = img1.getRGB(x, y); // if (colour != Image.BLACK) // return 0; if (x < img2.getWidth() && y < img2.getHeight() && img2.getRGB(x, y) == colour) return 0; int distance = 6; final int RANGE = 1; for (int x1 = x - RANGE; x1 <= x + RANGE; x1++) { if (distance == 1) break; if (x1 < 0 || x1 >= img2.getWidth()) continue; for (int y1 = y - (x1 - x); y1 <= y + RANGE; y1++) { if (y1 >= 0 && y1 < img2.getHeight() && img2.getRGB(x1, y1) == colour) { distance = Math.min(distance, Math.min(Math.abs(x - x1), Math.abs(y - y1))); }//ww w. j a v a2s .com } } return (distance * distance) / 2; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static int[][][] getRGBArray(BufferedImage imageIn) { // possible 10-fold speed increase in: // http://stackoverflow.com/questions/6524196/java-get-pixel-array-from-image // (but ensure all major bases are covered) int ImW = imageIn.getWidth(); int ImH = imageIn.getHeight(); Color tmpColor;//from w w w .ja v a2s . co m int[][][] rgbValues = new int[3][ImW][ImH]; for (int ii = 0; ii < ImW; ii++) { for (int jj = 0; jj < ImH; jj++) { tmpColor = new Color(imageIn.getRGB(ii, jj)); rgbValues[0][ii][jj] = tmpColor.getRed(); rgbValues[1][ii][jj] = tmpColor.getGreen(); rgbValues[2][ii][jj] = tmpColor.getBlue(); } } return rgbValues; }
From source file:cpcc.ros.services.RosImageConverterTest.java
/** * @param image the image to be checked. *///w w w .java2s .co m private void assertThatImageIsEmpty(BufferedImage image) { for (int y = 0; y < image.getHeight(); ++y) { for (int x = 0; x < image.getWidth(); ++x) { assertThat(image.getRGB(x, y)).overridingErrorMessage("Problem at x=%d, y=%d", x, y).isEqualTo(0); } } }