List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:com.actelion.research.orbit.imageAnalysis.utils.ImageUtils.java
/** * scales bands to min = 0 & max = 2^8 or 2^16 * * @param image/* w w w . j av a 2s. c o m*/ * @param min int[] containing minima per band * @param max * @return */ public static BufferedImage scaleIntensities(BufferedImage image, int[] min, int[] max) throws IllegalArgumentException { WritableRaster raster = image.getRaster(); if ((min.length != max.length) || min.length != raster.getNumBands()) throw new IllegalArgumentException( "Please ensure consistency of min and max arrays and number of bands in image"); int width = image.getWidth(); int height = image.getHeight(); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { for (int band = 0; band < raster.getNumBands(); band++) { int pixel = raster.getSample(col, row, band); if (pixel < min[band]) pixel = min[band]; if (pixel > max[band]) pixel = max[band]; pixel = ((int) (((((double) pixel - min[band]) / (max[band] - min[band])) * ((int) Math.pow(2, image.getColorModel().getPixelSize()) - 1)) + 0.5)); raster.setSample(col, row, band, pixel); } } } return image; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static float[][][] getImageDifference(BufferedImage image1, BufferedImage image2) { Color tmpColor1, tmpColor2;/* www . jav a 2 s. c o 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;/*w w w . j a va 2s . c om*/ 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:com.actelion.research.orbit.imageAnalysis.utils.ImageUtils.java
/** * Returns min and max intensities and percentiles 0.01, 0.05, 0.1, 0.9, 0.95, 0.99 of a BufferedImage. * * @param image/*from www. j ava 2 s . c om*/ * @return */ public static int[][] getMinMaxIntensitiesOfBI(BufferedImage image) { WritableRaster raster = image.getRaster(); // per band: { min, 1%, 5%, 10%, 90%, 95%, 99%, max } int[][] intensities = new int[raster.getNumBands()][8]; DescriptiveStatistics[] ds = new DescriptiveStatistics[raster.getNumBands()]; for (int i = 0; i < raster.getNumBands(); i++) ds[i] = new DescriptiveStatistics(); int width = image.getWidth(); int height = image.getHeight(); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { for (int band = 0; band < raster.getNumBands(); band++) { ds[band].addValue(raster.getSample(col, row, band)); } } } for (int i = 0; i < ds.length; i++) { intensities[i][0] = (int) ds[i].getMin(); intensities[i][1] = (int) ds[i].getPercentile(1); intensities[i][2] = (int) ds[i].getPercentile(5); intensities[i][3] = (int) ds[i].getPercentile(10); intensities[i][4] = (int) ds[i].getPercentile(90); intensities[i][5] = (int) ds[i].getPercentile(95); intensities[i][6] = (int) ds[i].getPercentile(99); intensities[i][7] = (int) ds[i].getMax(); } return intensities; }
From source file:edu.ku.brc.ui.GraphicsUtils.java
/** * @param orig the original image// w ww . j ava2 s .c o m * @param maxHeight the max height of the scaled image * @param maxWidth the max width of the scaled image * @param preserveAspectRatio if true, the scaling preserves the aspect ratio of the original image * @param doHighQuality do higher quality thumbnail (slow) * @return the byte array of the scaled image * @throws IOException an error occurred while encoding the result as a JPEG image */ public static byte[] scaleImage(final BufferedImage orig, final int maxHeight, final int maxWidth, final boolean preserveAspectRatio, boolean doHighQuality) throws IOException { BufferedImage scaled; if (true) { int targetW = maxWidth; int targetH = maxHeight; if (preserveAspectRatio) { int origWidth = orig.getWidth(); int origHeight = orig.getHeight(); double origRatio = (double) origWidth / (double) origHeight; double scaledRatio = (double) maxWidth / (double) maxHeight; if (origRatio > scaledRatio) { targetH = (int) (targetW / origRatio); } else { targetW = (int) (targetH * origRatio); } } scaled = getScaledInstance(orig, targetW, targetH, doHighQuality); } else { scaled = generateScaledImage(orig, RenderingHints.VALUE_INTERPOLATION_BILINEAR, Math.max(maxHeight, maxWidth)); } ByteArrayOutputStream output = new ByteArrayOutputStream(8192); ImageIO.write(scaled, "jpeg", output); byte[] outputBytes = output.toByteArray(); output.close(); return outputBytes; }
From source file:edu.stanford.epad.common.pixelmed.TIFFMasksToDSOConverter.java
public static BufferedImage convertRGBAToIndexed(BufferedImage src) { BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); dest.createGraphics().drawImage(src, 0, 0, null); return dest;// w ww. j a v a 2s . com }
From source file:de.mprengemann.intellij.plugin.androidicons.util.ImageUtils.java
public static BufferedImage resizeNinePatchImage(ImageInformation information) throws IOException { BufferedImage image = ImageIO.read(information.getImageFile()); if (MathUtils.floatEquals(information.getFactor(), 1f)) { return image; }/*w ww . jav a 2 s .c o m*/ BufferedImage trimmedImage = trim9PBorder(image); ImageInformation trimmedImageInformation = ImageInformation.newBuilder(information) .setExportName(getExportName("trimmed", information.getExportName())).build(); saveImageTempFile(trimmedImage, trimmedImageInformation); trimmedImage = resizeNormalImage(trimmedImage, trimmedImageInformation); saveImageTempFile(trimmedImage, ImageInformation.newBuilder(trimmedImageInformation) .setExportName(getExportName("trimmedResized", information.getExportName())).build()); BufferedImage borderImage; int w = trimmedImage.getWidth(); int h = trimmedImage.getHeight(); try { borderImage = generateBordersImage(image, w, h); } catch (Exception e) { return null; } int[] rgbArray = new int[w * h]; trimmedImage.getRGB(0, 0, w, h, rgbArray, 0, w); borderImage.setRGB(1, 1, w, h, rgbArray, 0, w); return borderImage; }
From source file:cognitivej.vision.overlay.builder.ImageOverlayBuilder.java
@NotNull private static BufferedImage copy(@NotNull BufferedImage img, int imageType) { int width = img.getWidth(); int height = img.getHeight(); BufferedImage newImage = new BufferedImage(width, height, imageType); Graphics g = newImage.createGraphics(); g.drawImage(img, 0, 0, null);//from w ww .j a v a2 s .c o m g.dispose(); return newImage; }
From source file:com.t3.persistence.PersistenceUtil.java
public static void saveToken(Token token, File file, boolean doWait) throws IOException { // Thumbnail// w w w . j ava2 s . c o m BufferedImage image = null; if (doWait) image = ImageManager.getImageAndWait(token.getImageAssetId()); else image = ImageManager.getImage(token.getImageAssetId()); Dimension sz = new Dimension(image.getWidth(), image.getHeight()); SwingUtil.constrainTo(sz, 50); BufferedImage thumb = new BufferedImage(sz.width, sz.height, BufferedImage.TRANSLUCENT); Graphics2D g = thumb.createGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(image, 0, 0, sz.width, sz.height, null); g.dispose(); PackedFile pakFile = null; try { pakFile = new PackedFile(file); saveAssets(token.getAllImageAssets(), pakFile); pakFile.putFile(Token.FILE_THUMBNAIL, ImageUtil.imageToBytes(thumb, "png")); pakFile.setContent(token); pakFile.save(); } finally { if (pakFile != null) pakFile.close(); } }
From source file:ImageOpByRomain.java
/** * <p>/*from w ww . java 2 s. c o m*/ * Returns a new compatible image with the same width, height and transparency * as the image specified as a parameter. * </p> * * @see java.awt.Transparency * @see #createCompatibleImage(int, int) * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int) * @see #createTranslucentCompatibleImage(int, int) * @see #loadCompatibleImage(java.net.URL) * @see #toCompatibleImage(java.awt.image.BufferedImage) * @param image * the reference image from which the dimension and the * transparency of the new image are obtained * @return a new compatible <code>BufferedImage</code> with the same * dimension and transparency as <code>image</code> */ public static BufferedImage createCompatibleImage(BufferedImage image) { return createCompatibleImage(image, image.getWidth(), image.getHeight()); }