org.openimaj.image.feature.local.detector.mser.gui
Class ImageUtils

java.lang.Object
  extended by org.openimaj.image.feature.local.detector.mser.gui.ImageUtils

public class ImageUtils
extends Object

Some useful image utility functions.

Version:
$Author$, $Revision$, $Date$
Author:
David Dupplaw

Nested Class Summary
static class ImageUtils.ImagePanel
          Draws an image scaled to the size of the component.
 
Constructor Summary
ImageUtils()
           
 
Method Summary
static BufferedImage convertToGreyscale(BufferedImage img)
          Converts the given image to a greyscale buffered image.
static BufferedImage copyImage(BufferedImage source)
          Creates a copy of a BufferedImage
static void displayImage(BufferedImage img)
          Displays the give image in a window.
static byte[][] getGrayscaleData(BufferedImage img)
          Returns grey-scale image data (0-255) for the given image.
static BufferedImage getScaledInstance(BufferedImage img, int targetWidthIn, int targetHeightIn, Object hint, boolean higherQuality, boolean keepAspect)
          Convenience method that returns a scaled instance of the provided BufferedImage.
static BufferedImage invertImage(BufferedImage img, boolean newImage)
          Inverts the given image.
static BufferedImage loadImage(File f)
          Load an image from the given file.
static BufferedImage loadImage(InputStream in)
          Load an image from the given input stream
static void saveImage(OutputStream out, BufferedImage image, String formatName)
          Writes the given image to the given output stream in the given format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

getGrayscaleData

public static byte[][] getGrayscaleData(BufferedImage img)
Returns grey-scale image data (0-255) for the given image. If the image is a colour RGB image, the average of RGB is taken.

Parameters:
img - The image to return the greyscale data for.
Returns:
The greyscale data for the image as 2D byte array.

convertToGreyscale

public static BufferedImage convertToGreyscale(BufferedImage img)
Converts the given image to a greyscale buffered image.

Parameters:
img - A colour image
Returns:
A greyscale image.

copyImage

public static BufferedImage copyImage(BufferedImage source)
Creates a copy of a BufferedImage

Parameters:
source - The image to copy
Returns:
A copy of the source image

loadImage

public static BufferedImage loadImage(File f)
Load an image from the given file.

Parameters:
f - The file to load the image from
Returns:
a BufferedImage containing the image loaded, or null

loadImage

public static BufferedImage loadImage(InputStream in)
Load an image from the given input stream

Parameters:
in - The InputStream to load the image from
Returns:
A BufferedImage or null

saveImage

public static void saveImage(OutputStream out,
                             BufferedImage image,
                             String formatName)
Writes the given image to the given output stream in the given format.

Parameters:
out - The output stream to write to
image - The image to write
formatName - The format to write the image in

getScaledInstance

public static BufferedImage getScaledInstance(BufferedImage img,
                                              int targetWidthIn,
                                              int targetHeightIn,
                                              Object hint,
                                              boolean higherQuality,
                                              boolean keepAspect)
Convenience method that returns a scaled instance of the provided BufferedImage. From http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html

Parameters:
img - the original image to be scaled
targetWidthIn - the desired width of the scaled instance, in pixels
targetHeightIn - the desired height of the scaled instance, in pixels
hint - one of the rendering hints that corresponds to RenderingHints.KEY_INTERPOLATION (e.g. RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RenderingHints.VALUE_INTERPOLATION_BICUBIC)
higherQuality - if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, where targetWidth or targetHeight is smaller than the original dimensions, and generally only when the BILINEAR hint is specified)
keepAspect - if TRUE will make image fit within targetWidthIn x targetHeightIn
Returns:
a scaled version of the original BufferedImage

invertImage

public static BufferedImage invertImage(BufferedImage img,
                                        boolean newImage)
Inverts the given image.

Parameters:
img - The image to invert
newImage - Whether to return a new image or invert the given image.
Returns:
the inverted image

displayImage

public static void displayImage(BufferedImage img)
Displays the give image in a window.

Parameters:
img - The image to display


Copyright © 2011 The University of Southampton. All Rights Reserved.