-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from Samyssmile/feature/augmentation-example
Implementation of Single Image Augmentation Example
- Loading branch information
Showing
11 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
example/src/main/java/de/example/augmentation/MultiImageAugmentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
example/src/main/java/de/example/augmentation/SingleImageAugmentationExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+210 Bytes
.../src/main/resources/images/small-julia/6e0f85fc-9592-464b-b1e5-bf3bafecce98.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+209 Bytes
.../src/main/resources/images/small-julia/6e40d4a6-4a33-4c47-9348-c9981fe04b8c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+179 Bytes
.../src/main/resources/images/small-julia/6f48ddbf-d9b2-4e40-8d66-9702c9fe25bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+213 Bytes
.../src/main/resources/images/small-julia/6f678a19-76ec-4e46-9a7f-eef44551720b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+221 Bytes
.../src/main/resources/images/small-julia/6f6b4894-7630-4c9d-98df-fdfa00c986a9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+243 Bytes
.../src/main/resources/images/small-julia/8dfcc595-0be2-44eb-80f5-4657e175fa3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+226 Bytes
.../src/main/resources/images/small-julia/9b2d66f8-2bf8-440a-99a1-f4d89f3eb88c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.