Class ImageUtils
- java.lang.Object
-
- adams.gui.visualization.segmentation.ImageUtils
-
public class ImageUtils extends Object
Helper class for image related operations.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description ImageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
combineImages(BufferedImage source, BufferedImage target)
Transfers all the non-black pixels from the source image into the target one.static void
fill(BufferedImage image, Point n, Color targetColor, Color replacementColor)
Performs flood-fill on the provided image.static void
initImage(BufferedImage image, Color color)
Replaces any non-black pixels with the specified color.static BufferedImage
newImage(int width, int height)
Creates a new image with just black pixels.static boolean
replaceColor(int[] pixels, int width, int height, Color oldColor, Color newColor, int[] rangeX, int[] rangeY)
Replaces the old color with the new one.static boolean
replaceColor(int[] pixels, Color oldColor, Color newColor)
Replaces the old color with the new one.static boolean
replaceColor(BufferedImage image, Color oldColor, Color newColor)
Replaces the old color with the new one.static boolean
replaceColor(BufferedImage image, Color oldColor, Color newColor, int[] rangeX, int[] rangeY)
Replaces the old color with the new one.protected static boolean
requiresReplacement(int pixel, Integer target, int replacement)
Checks whether the pixel requires replacement.
-
-
-
Method Detail
-
combineImages
public static void combineImages(BufferedImage source, BufferedImage target)
Transfers all the non-black pixels from the source image into the target one.- Parameters:
source
- the source imagetarget
- the target image
-
replaceColor
public static boolean replaceColor(int[] pixels, Color oldColor, Color newColor)
Replaces the old color with the new one.- Parameters:
pixels
- the pixels to processoldColor
- the old color to replacenewColor
- the replacement color- Returns:
- true if modified
-
replaceColor
public static boolean replaceColor(BufferedImage image, Color oldColor, Color newColor)
Replaces the old color with the new one.- Parameters:
image
- the image to processoldColor
- the old color to replacenewColor
- the replacement color- Returns:
- true if modified
-
replaceColor
public static boolean replaceColor(int[] pixels, int width, int height, Color oldColor, Color newColor, int[] rangeX, int[] rangeY)
Replaces the old color with the new one.- Parameters:
pixels
- the pixels to processwidth
- the width of the imageheight
- the height of the imageoldColor
- the old color to replacenewColor
- the replacement colorrangeX
- the sub-range of x coordinates to work on (both incl)rangeY
- the sub-range of y coordinates to work on (both incl)- Returns:
- true if modified
-
replaceColor
public static boolean replaceColor(BufferedImage image, Color oldColor, Color newColor, int[] rangeX, int[] rangeY)
Replaces the old color with the new one.- Parameters:
image
- the image to processoldColor
- the old color to replacenewColor
- the replacement colorrangeX
- the sub-range of x coordinates to work on (both incl)rangeY
- the sub-range of y coordinates to work on (both incl)- Returns:
- true if modified
-
initImage
public static void initImage(BufferedImage image, Color color)
Replaces any non-black pixels with the specified color.- Parameters:
image
- the image to processcolor
- the new color for non-black pixels
-
newImage
public static BufferedImage newImage(int width, int height)
Creates a new image with just black pixels.- Parameters:
width
- the width of the imageheight
- the height of the image
-
requiresReplacement
protected static boolean requiresReplacement(int pixel, Integer target, int replacement)
Checks whether the pixel requires replacement. If target is not null, then the pixel must match that RGB value. If target is null, then the pixel must be difference from the replacement RGB value.- Parameters:
pixel
- the pixel to checktarget
- the target RGB to replace, can be nullreplacement
- the replacement RGB to use- Returns:
- true if pixel requires replacing
-
fill
public static void fill(BufferedImage image, Point n, Color targetColor, Color replacementColor)
Performs flood-fill on the provided image. Based on pseudo code from here: https://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations- Parameters:
image
- the image to updaten
- the starting pointtargetColor
- the color to replace, can be null to apply to any colorreplacementColor
- the replacement color
-
-