List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
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; }/* w w w . j a va 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 ww w . j ava2 s. c om } return values; }
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 2 s . c o m 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:com.uksf.mf.core.utility.loaders.ImageLoad.java
/** * Changes colour of all non-transparent pixels for given image to given colour * @param image - image to change colours in * @param newColour colour to change to/* w w w. ja va 2s.c o m*/ * @return image with changed colours */ private static ImageIcon changeImageColour(ImageIcon image, int newColour) { LogHandler.logSeverity(INFO, "Converting image: " + image + " colour to: " + newColour); BufferedImage bufferedImage = new BufferedImage(image.getIconWidth(), image.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics graphics = bufferedImage.createGraphics(); image.paintIcon(null, graphics, 0, 0); graphics.dispose(); for (int x = 0; x < bufferedImage.getWidth(); x++) { for (int y = 0; y < bufferedImage.getHeight(); y++) { int colour = bufferedImage.getRGB(x, y); colour = (((colour >> 24) & 0xff) << 24) | (((colour & 0x00ff0000) >> 16) << 16) | (((colour & 0x0000ff00) >> 8) << 8) | (colour & 0x000000ff); if (colour != COLOUR_TRANSPARENT.getRGB()) { newColour = (((colour >> 24) & 0xff) << 24) | (((newColour & 0x00ff0000) >> 16) << 16) | (((newColour & 0x0000ff00) >> 8) << 8) | (newColour & 0x000000ff); bufferedImage.setRGB(x, y, newColour); } } } return new ImageIcon(bufferedImage); }
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 av a 2 s. co 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.opendesign.utils.ThumbnailManager.java
/** * ?? ? //ww w .j a va 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); } }
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 . j a v a 2s . 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[] 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:ImageProcessing.ImageProcessing.java
public static void processFlipHorizontal(BufferedImage image) { //Flips image horizontally. for (int i = 0; i < image.getHeight(); i++) { for (int j = 0; j < image.getWidth() / 2; j++) { int left_rgb = image.getRGB(j, i); int right_rgb = image.getRGB(image.getWidth() - (j + 1), i); image.setRGB(j, i, right_rgb); image.setRGB(image.getWidth() - (j + 1), i, left_rgb); }//from w w w . j a va 2 s . co m } }
From source file:ImageProcessing.ImageProcessing.java
public static void processFlipVertical(BufferedImage image) { //Flips image vertically. for (int i = 0; i < image.getHeight() / 2; i++) { for (int j = 0; j < image.getWidth(); j++) { int upper_rgb = image.getRGB(j, i); int below_rgb = image.getRGB(j, image.getHeight() - (i + 1)); image.setRGB(j, i, below_rgb); image.setRGB(j, image.getHeight() - (i + 1), upper_rgb); }/* w w w. java2 s. c o m*/ } }
From source file:ConvertUtil.java
/** * Converts the source to 1-bit colour depth (monochrome). No transparency. * // w w w. jav a 2 s . co m * @param src * the source image to convert * @return a copy of the source image with a 1-bit colour depth. */ public static BufferedImage convert1(BufferedImage src) { IndexColorModel icm = new IndexColorModel(1, 2, new byte[] { (byte) 0, (byte) 0xFF }, new byte[] { (byte) 0, (byte) 0xFF }, new byte[] { (byte) 0, (byte) 0xFF }); BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_BINARY, icm); ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(), dest.getColorModel().getColorSpace(), null); cco.filter(src, dest); return dest; }