From e96806b6edf4f215e3a6b911f9323a61cf6f0149 Mon Sep 17 00:00:00 2001 From: Ysobel Date: Thu, 2 Feb 2023 09:03:46 +1100 Subject: [PATCH 1/3] Fix the CPU engine --- cpp/visualmesh/engine/cpu/engine.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/visualmesh/engine/cpu/engine.hpp b/cpp/visualmesh/engine/cpu/engine.hpp index 9fc76e6..f69e9b9 100644 --- a/cpp/visualmesh/engine/cpu/engine.hpp +++ b/cpp/visualmesh/engine/cpu/engine.hpp @@ -269,7 +269,7 @@ namespace engine { return ClassifiedMesh{std::move(projected.pixel_coordinates), std::move(projected.neighbourhood), std::move(projected.global_indices), - input}; + std::move(input)}; } /** From 64c49fce3a17bbee73339eaee556f47a80b93c40 Mon Sep 17 00:00:00 2001 From: Ysobel Date: Thu, 2 Feb 2023 09:04:20 +1100 Subject: [PATCH 2/3] Fix holes in the mesh --- cpp/visualmesh/visualmesh.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/visualmesh/visualmesh.hpp b/cpp/visualmesh/visualmesh.hpp index 4804765..f8539c8 100644 --- a/cpp/visualmesh/visualmesh.hpp +++ b/cpp/visualmesh/visualmesh.hpp @@ -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: From c1945ba44daf37c2e57c1c6ad9c7b1eb6ce7525d Mon Sep 17 00:00:00 2001 From: Blake Bodycote Date: Thu, 7 Dec 2023 21:43:24 +1100 Subject: [PATCH 3/3] Adds a stand-alone python script that visualises image augmentation, along with an example config file of augmentation settings --- example/augmentation_visualisation.py | 40 +++++++++++++++++++++++++++ example/augmentations_example.yaml | 17 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 example/augmentation_visualisation.py create mode 100644 example/augmentations_example.yaml diff --git a/example/augmentation_visualisation.py b/example/augmentation_visualisation.py new file mode 100644 index 0000000..1e9f794 --- /dev/null +++ b/example/augmentation_visualisation.py @@ -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() diff --git a/example/augmentations_example.yaml b/example/augmentations_example.yaml new file mode 100644 index 0000000..7dbc7a7 --- /dev/null +++ b/example/augmentations_example.yaml @@ -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 }