Skip to content

Commit

Permalink
Merge pull request #128 from Samyssmile/feature/augmentation-example
Browse files Browse the repository at this point in the history
Implementation of Single Image Augmentation Example
  • Loading branch information
Samyssmile authored Nov 19, 2023
2 parents 48c3fa9 + ac4f782 commit af7e825
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ gradle.properties
!gradle.properties
!**/src/main/**/gradle.properties

### Images
*.jpg
*.jpeg
*.png
/benchmark-data/augmentation-benchmark-images/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.example.augmentation;

import de.edux.augmentation.core.AugmentationBuilder;
import de.edux.augmentation.core.AugmentationSequence;
import de.edux.augmentation.effects.ColorEqualizationAugmentation;
import de.edux.augmentation.effects.ResizeAugmentation;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import static de.example.augmentation.SingleImageAugmentationExample.loadTestImage;

public class MultiImageAugmentation {
private static final String IMAGE_DIR = "example" + File.separator +
"src" + File.separator + "main" + File.separator +
"resources"+ File.separator +
"images" + File.separator + "small-julia";

private static final Integer TARGET_WIDTH = 250;
private static final Integer TARGET_HEIGHT = 250;
private static final int TWO_CPU_WORKERS = 2;

public static void main(String[] args) throws IOException, InterruptedException {
String projectRootPath = new File("").getAbsolutePath();
String imageDirPath = projectRootPath + File.separator + IMAGE_DIR;
String outputFolder = imageDirPath +File.separator+ "augmented";

AugmentationSequence augmentationSequence =
new AugmentationBuilder()
.addAugmentation(new ResizeAugmentation(TARGET_WIDTH, TARGET_HEIGHT))
.addAugmentation(new ColorEqualizationAugmentation())
.build()
.run(imageDirPath, TWO_CPU_WORKERS, outputFolder);

openFolder(outputFolder);
}

private static void openFolder(String outputFolder) throws IOException {
File augmentedImagesDir = new File(outputFolder);
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(augmentedImagesDir);
} else {
System.out.println(
"No Desktop support. Please open the augmented images directory manually.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package de.example.augmentation;

import de.edux.augmentation.core.AugmentationBuilder;
import de.edux.augmentation.core.AugmentationSequence;
import de.edux.augmentation.effects.ColorEqualizationAugmentation;
import de.edux.augmentation.effects.ResizeAugmentation;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class SingleImageAugmentationExample {
private static final String IMAGE_PATH = "images" + File.separator + "cyborg.png";
private static final Integer TARGET_WIDTH = 250;
private static final Integer TARGET_HEIGHT = 250;

public static void main(String[] args) throws IOException {
// Get Buffered Image from image file

BufferedImage bufferedImage = loadTestImage(IMAGE_PATH);


AugmentationSequence augmentationSequence=
new AugmentationBuilder()
.addAugmentation(new ResizeAugmentation(TARGET_WIDTH,TARGET_HEIGHT))
.addAugmentation(new ColorEqualizationAugmentation())
.build();

BufferedImage augmentedImage=augmentationSequence.applyTo(bufferedImage);

System.out.println(augmentedImage);


}

public static BufferedImage loadTestImage(String path) throws IOException {
var resourcePath = path;
var imageStream =
SingleImageAugmentationExample.class.getClassLoader().getResourceAsStream(resourcePath);
if (imageStream == null) {
throw new IOException("Cannot find resource: " + resourcePath);
}
return ImageIO.read(imageStream);
}
}
Binary file added example/src/main/resources/images/cyborg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af7e825

Please sign in to comment.