-
Notifications
You must be signed in to change notification settings - Fork 17
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 #124 from Samyssmile/chore/shaman
chore(): shaman image added
- Loading branch information
Showing
2 changed files
with
80 additions
and
74 deletions.
There are no files selected for viewing
154 changes: 80 additions & 74 deletions
154
lib/src/test/java/de/edux/augmentation/effects/BrightnessAugmentationTest.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 |
---|---|---|
@@ -1,94 +1,100 @@ | ||
package de.edux.augmentation.effects; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import static de.edux.augmentation.AugmentationTestUtils.loadTestImage; | ||
import static de.edux.augmentation.AugmentationTestUtils.openImageInPreview; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
|
||
import static de.edux.augmentation.AugmentationTestUtils.loadTestImage; | ||
import static de.edux.augmentation.AugmentationTestUtils.openImageInPreview; | ||
import javax.imageio.ImageIO; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class BrightnessAugmentationTest { | ||
|
||
private BufferedImage originalImage; | ||
private BufferedImage augmentedImage; | ||
|
||
|
||
@AfterEach | ||
public void checkConformity() throws IOException { | ||
int[] originalPixels = | ||
originalImage.getRGB(0, 0, originalImage.getWidth(), originalImage.getHeight(), null, 0, originalImage.getWidth()); | ||
int[] augmentedPixels = | ||
augmentedImage.getRGB( | ||
0, | ||
0, | ||
augmentedImage.getWidth(), | ||
augmentedImage.getHeight(), | ||
null, | ||
0, | ||
augmentedImage.getWidth()); | ||
|
||
assertNotNull(augmentedImage, "Augmented image should not be null."); | ||
|
||
assertEquals( | ||
originalImage.getWidth(), | ||
augmentedImage.getWidth(), | ||
"Augmented image width should match the specified width."); | ||
assertEquals( | ||
originalImage.getHeight(), | ||
augmentedImage.getHeight(), | ||
"Augmented image height should match the specified height."); | ||
assertFalse( | ||
Arrays.equals(originalPixels, augmentedPixels), | ||
"The augmented image should differ from the original."); | ||
|
||
Path outputPath = Paths.get("augmented.png"); | ||
ImageIO.write(augmentedImage, "png", outputPath.toFile()); | ||
|
||
assertTrue(Files.exists(outputPath), "Output image file should exist."); | ||
assertTrue(Files.size(outputPath) > 0, "Output image file should not be empty."); | ||
} | ||
@Test | ||
public void shouldIncreaseBrightness() throws IOException, InterruptedException { | ||
originalImage = loadTestImage("augmentation" + File.separator + "fireworks.png"); | ||
|
||
double testValue = 0.5; | ||
BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); | ||
augmentedImage = augmentation.apply(originalImage); | ||
|
||
for (int y = 0; y < originalImage.getHeight(); y++){ | ||
for (int x = 0; x < originalImage.getWidth(); x++){ | ||
assertTrue(originalImage.getRGB(x,y) <= augmentedImage.getRGB(x,y)); | ||
} | ||
} | ||
|
||
openImageInPreview(originalImage); | ||
openImageInPreview(augmentedImage); | ||
private BufferedImage originalImage; | ||
private BufferedImage augmentedImage; | ||
|
||
@AfterEach | ||
public void checkConformity() throws IOException { | ||
int[] originalPixels = | ||
originalImage.getRGB( | ||
0, | ||
0, | ||
originalImage.getWidth(), | ||
originalImage.getHeight(), | ||
null, | ||
0, | ||
originalImage.getWidth()); | ||
int[] augmentedPixels = | ||
augmentedImage.getRGB( | ||
0, | ||
0, | ||
augmentedImage.getWidth(), | ||
augmentedImage.getHeight(), | ||
null, | ||
0, | ||
augmentedImage.getWidth()); | ||
|
||
assertNotNull(augmentedImage, "Augmented image should not be null."); | ||
|
||
assertEquals( | ||
originalImage.getWidth(), | ||
augmentedImage.getWidth(), | ||
"Augmented image width should match the specified width."); | ||
assertEquals( | ||
originalImage.getHeight(), | ||
augmentedImage.getHeight(), | ||
"Augmented image height should match the specified height."); | ||
assertFalse( | ||
Arrays.equals(originalPixels, augmentedPixels), | ||
"The augmented image should differ from the original."); | ||
|
||
Path outputPath = Paths.get("augmented.png"); | ||
ImageIO.write(augmentedImage, "png", outputPath.toFile()); | ||
|
||
assertTrue(Files.exists(outputPath), "Output image file should exist."); | ||
assertTrue(Files.size(outputPath) > 0, "Output image file should not be empty."); | ||
} | ||
|
||
@Test | ||
public void shouldIncreaseBrightness() throws IOException, InterruptedException { | ||
originalImage = loadTestImage("augmentation" + File.separator + "shaman-shadows.png"); | ||
|
||
double testValue = 0.35; | ||
BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); | ||
augmentedImage = augmentation.apply(originalImage); | ||
|
||
for (int y = 0; y < originalImage.getHeight(); y++) { | ||
for (int x = 0; x < originalImage.getWidth(); x++) { | ||
assertTrue(originalImage.getRGB(x, y) <= augmentedImage.getRGB(x, y)); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldDecreaseBrightness() throws IOException, InterruptedException { | ||
originalImage = loadTestImage("augmentation" + File.separator + "national-park.png"); | ||
openImageInPreview(originalImage); | ||
openImageInPreview(augmentedImage); | ||
} | ||
|
||
double testValue= -0.5; | ||
BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); | ||
augmentedImage = augmentation.apply(originalImage); | ||
@Test | ||
public void shouldDecreaseBrightness() throws IOException, InterruptedException { | ||
originalImage = loadTestImage("augmentation" + File.separator + "shaman-shadows.png"); | ||
|
||
for (int y = 0; y < originalImage.getHeight(); y++){ | ||
for (int x = 0; x < originalImage.getWidth(); x++){ | ||
assertTrue(originalImage.getRGB(x,y) >= augmentedImage.getRGB(x,y)); | ||
} | ||
} | ||
double testValue = -0.5; | ||
BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); | ||
augmentedImage = augmentation.apply(originalImage); | ||
|
||
openImageInPreview(originalImage); | ||
openImageInPreview(augmentedImage); | ||
for (int y = 0; y < originalImage.getHeight(); y++) { | ||
for (int x = 0; x < originalImage.getWidth(); x++) { | ||
assertTrue(originalImage.getRGB(x, y) >= augmentedImage.getRGB(x, y)); | ||
} | ||
} | ||
|
||
openImageInPreview(originalImage); | ||
openImageInPreview(augmentedImage); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.