Skip to content

Commit

Permalink
Merge pull request #124 from Samyssmile/chore/shaman
Browse files Browse the repository at this point in the history
chore(): shaman image added
  • Loading branch information
Samyssmile authored Nov 12, 2023
2 parents f9a2a0f + e659255 commit 8364d5c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 74 deletions.
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.

0 comments on commit 8364d5c

Please sign in to comment.