public final class ImageUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
createIndexFile(HashMap<File,BufferedImage> imageMap,
String imageFile,
boolean useAbsPath) |
static List<BufferedImage> |
cropAtCornersAndCenter(BufferedImage img,
int cropWidth,
int cropHeight)
Returns five crops of a given image: four from each corner and one at center
|
static BufferedImage |
flipHorizontal(BufferedImage img) |
static BufferedImage |
flipVertical(BufferedImage img) |
static void |
generateNoisyImage(int width,
int height,
int numberOfImages,
String destPath) |
static void |
generateRandomColoredImages(int width,
int height,
int numberOfImages,
String destPath)
Generates a specified number of randomly full colored images of a specified size.
|
static void |
generateRandomFilledRectImages(int width,
int height,
int numberOfImages,
String destPath) |
static String |
getImageType(File file)
Returns the extension of the given image file.
|
static BufferedImage |
grayscale(BufferedImage img)
Returns grayscale version of the given image.
|
static HashMap<File,BufferedImage> |
loadFileImageMapFromDirectory(File dir)
Loads JPG, JPEG or PNG images from specified directory and returns them as a map
with File object as a key and BufferedImage object as a value.
|
static List<BufferedImage> |
loadImagesFromDirectory(File dir)
Loads all images from the specified directory, and returns them as a list.
|
static BufferedImage |
randomCrop(BufferedImage img,
int cropWidth,
int cropHeight)
Randomly crop image with specified width and height.
|
static List<BufferedImage> |
randomCrop(BufferedImage img,
int cropWidth,
int cropHeight,
int cropNum,
Random random)
Crops specified number of random sub-images with specified dimensions.
|
static BufferedImage |
randomTintAndBrightness(BufferedImage img) |
static List<BufferedImage> |
randomTintAndBrightness(BufferedImage img,
float maxTint,
int maxBrightness,
int num,
Random random)
Still not working as it should
|
static BufferedImage[] |
randomTranslateImage(BufferedImage img,
int stepCount,
int stepSize)
Returns an array of images created by translating specified input image
by specified number of count with specified step size.
|
static BufferedImage |
scaleAndCenter(BufferedImage img,
int targetWidth,
int targetHeight,
int padding,
Color bgColor)
Scales input image to specified target width or height, centers and returns resulting image.
|
static BufferedImage |
scaleBySmallerAndCrop(BufferedImage img,
int targetWidth,
int targetHeight)
Scales input image to specified target width or height, crops and returns resulting image.
|
static BufferedImage |
scaleBySmallerTarget(BufferedImage img,
int targetWidth,
int targetHeight) |
static BufferedImage |
scaleImage(BufferedImage img,
int newWidth,
int newHeight)
Scales specified image to given size and returns new image with specified width and height.
|
static List<BufferedImage> |
translateImage(BufferedImage img)
Generates 4 translated variations of the given image: translates it for one third of an image width and height in each direction.
|
static void |
writeImages(List<BufferedImage> images,
String targetPath,
String fileNamePrefix,
String fileType)
Writes list of images to specified file path.
|
public static List<BufferedImage> translateImage(BufferedImage img)
img
- image to translatepublic static BufferedImage scaleImage(BufferedImage img, int newWidth, int newHeight)
img
- image to sclaenewWidth
- width of scaled imagenewHeight
- height of scaled imagepublic static BufferedImage scaleAndCenter(BufferedImage img, int targetWidth, int targetHeight, int padding, Color bgColor)
img
- image to scaletargetWidth
- witdth to scale totargetHeight
- height to scale topadding
- minimalno rastojanje od ivica slike koja se smanjuje i centrirabgColor,
- umesto bgColor bolje da bude neki pattern koji popinjava tipa random pixelspublic static BufferedImage scaleBySmallerAndCrop(BufferedImage img, int targetWidth, int targetHeight)
img
- image to scaletargetWidth
- target image widthtargetHeight
- target image heightpublic static BufferedImage scaleBySmallerTarget(BufferedImage img, int targetWidth, int targetHeight)
public static BufferedImage flipHorizontal(BufferedImage img)
public static BufferedImage flipVertical(BufferedImage img)
public static List<BufferedImage> loadImagesFromDirectory(File dir) throws IOException
dir
- IOException
public static HashMap<File,BufferedImage> loadFileImageMapFromDirectory(File dir) throws IOException
dir
- directory to loadIOException
public static String getImageType(File file)
file
- public static BufferedImage grayscale(BufferedImage img)
img
- public static void createIndexFile(HashMap<File,BufferedImage> imageMap, String imageFile, boolean useAbsPath) throws IOException
imageMap
- imageFile
- useAbsPath
- IOException
public static BufferedImage[] randomTranslateImage(BufferedImage img, int stepCount, int stepSize)
img
- image to translatestepCount
- number ofstepSize
- public static List<BufferedImage> randomCrop(BufferedImage img, int cropWidth, int cropHeight, int cropNum, Random random)
img
- image to cropcropWidth
- width of the cropped imagecropHeight
- height of the cropped imagecropNum
- number of images to croprandom
- random number generator used to generate random positionspublic static List<BufferedImage> cropAtCornersAndCenter(BufferedImage img, int cropWidth, int cropHeight)
img
- image to cropcropWidth
- width of the cropped areacropHeight
- height of the cropped areapublic static BufferedImage randomCrop(BufferedImage img, int cropWidth, int cropHeight)
img
- cropWidth
- cropHeight
- public static List<BufferedImage> randomTintAndBrightness(BufferedImage img, float maxTint, int maxBrightness, int num, Random random)
img
- tint
- brightness
- public static BufferedImage randomTintAndBrightness(BufferedImage img)
public static void writeImages(List<BufferedImage> images, String targetPath, String fileNamePrefix, String fileType) throws IOException
images
- images to writetargetPath
- path to write tofileNamePrefix
- prefix of image file name to use (eg. for prefix pattern "someImage" it will create file someImage_1.jpg )fileType
- type of file/images to writeIOException
public static void generateRandomColoredImages(int width, int height, int numberOfImages, String destPath) throws IOException
width
- image widthheight
- image heightnumberOfImages
- number of images to generatedestPath
- destination path to save imagesIOException
public static void generateRandomFilledRectImages(int width, int height, int numberOfImages, String destPath) throws IOException
IOException
public static void generateNoisyImage(int width, int height, int numberOfImages, String destPath) throws IOException
IOException
Copyright © 2022. All rights reserved.