From ce2c317d149189a7e5e77419ad0908650d6af058 Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Tue, 13 Oct 2020 01:01:19 -0400 Subject: [PATCH] Update shuffle.py Changed hues to reflect the number of unique classes. Seems like both hue=0 and hue=255 look red. Restricted upper-bound of hue to 200 (violet) to differentiate the two. --- shuffle.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shuffle.py b/shuffle.py index 3912d4e..7864f2a 100644 --- a/shuffle.py +++ b/shuffle.py @@ -61,11 +61,19 @@ def log_4(n): def make_hilbert_png(ordering, png_filename): '''Takes a shuffled list of integers 0...n and visualizes it as an image.''' hilbert_order = log_4(len(ordering)) - hues = np.linspace(0, 255, len(ordering)) + + order_to_hue_index_map = dict() + for index, order in enumerate(set(ordering)): + order_to_hue_index_map[order] = index + 1 + + # Add one to represent unmodified pixels + hues = np.linspace(0, 200, len(order_to_hue_index_map)+1) + image_dims = 2 ** hilbert_order image_array = np.zeros([image_dims, image_dims, 3]) for index, coord in zip(ordering, hilbert_curve(hilbert_order)): - image_array[coord][0] = hues[index] + image_array[coord][0] = hues[order_to_hue_index_map[index]] + image_array[:, :, 1] = SATURATION image_array[:, :, 2] = VALUE image_array = image_array.astype(np.uint8)