Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augmentation visualisation #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/visualmesh/engine/cpu/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace engine {
return ClassifiedMesh<Scalar, N_NEIGHBOURS>{std::move(projected.pixel_coordinates),
std::move(projected.neighbourhood),
std::move(projected.global_indices),
input};
std::move(input)};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/visualmesh/visualmesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class VisualMesh {
// z height from the transformation matrix
const Scalar& h = Hoc[2][3];
auto mesh = height(h);
return mesh->lookup(Hoc, lens);
return std::make_pair(mesh, mesh.lookup(Hoc, lens));
}

private:
Expand Down
40 changes: 40 additions & 0 deletions example/augmentation_visualisation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import tensorflow as tf
import matplotlib.pyplot as plt
import yaml

image_path = "images/image0000002.jpg"
config_path = "augmentations_example.yaml"

# Decode image into tensor
image = open(image_path, 'rb').read()
image_tensor = tf.image.decode_jpeg(image)

# Get augmentations
with open(config_path, "r") as file:
data = yaml.safe_load(file)
augmentations = data["example"]["config"]["augmentations"]

# Apply the augmentations that were listed
if "brightness" in augmentations:
v = augmentations["brightness"]
image_tensor = tf.image.adjust_brightness(image_tensor, tf.random.truncated_normal(shape=(), **v))
if "contrast" in augmentations:
v = augmentations["contrast"]
image_tensor = tf.image.adjust_contrast(image_tensor, tf.random.truncated_normal(shape=(), **v))
if "hue" in augmentations:
v = augmentations["hue"]
image_tensor = tf.image.adjust_hue(image_tensor, tf.random.truncated_normal(shape=(), **v))
if "saturation" in augmentations:
v = augmentations["saturation"]
image_tensor = tf.image.adjust_saturation(image_tensor, tf.random.truncated_normal(shape=(), **v))
if "gamma" in augmentations:
v_gamma = augmentations["gamma"]["gamma"]
v_gain = augmentations["gamma"]["gain"]
image_tensor = tf.image.adjust_gamma(
image_tensor, tf.random.truncated_normal(shape=(), **v_gamma), tf.random.truncated_normal(shape=(), **v_gain)
)

# Display image using matplotlib
plt.imshow(image_tensor)
plt.axis('off')
plt.show()
17 changes: 17 additions & 0 deletions example/augmentations_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

example:
type: Image
config:
augmentations:
# Adjust the brightness `x + delta`
brightness: { mean: 0, stddev: 0.05 }
# Adjust the contrast `(x - mean) * delta + mean`
contrast: { mean: 1, stddev: 0.05 }
# Convert to hsv, adjust the hue by a value from [-1 -> 1] and back to rgb
hue: { mean: 0, stddev: 0.05 }
# Convert to hsv, multiply saturation by value and convert back to rgb
saturation: { mean: 1, stddev: 0.05 }
# Adjust the gamma `gain * x**gamma`
gamma:
gamma: { mean: 1, stddev: 0.05 }
gain: { mean: 1, stddev: 0.05 }