Skip to content

Commit

Permalink
V2.1 First ping finish
Browse files Browse the repository at this point in the history
- first ping result with lower res
- Higher res version could be download at https://drive.google.com/file/d/1bJCthywxjfU5lVKnAav8i1T5MJmGmbfx/view?usp=sharing
  • Loading branch information
StevenLi-phoenix committed Feb 26, 2023
1 parent 07ba121 commit d35b2f6
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
82 changes: 82 additions & 0 deletions all_256_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# import os
# from PIL import Image
# from hilbertcurve.hilbertcurve import HilbertCurve
from tqdm import tqdm
#
# # Number of images
# num_images = 256
#
# # Image size (assuming all images have the same size)
# image_size = (4096, 4096)
#
# # Determine the order of the Hilbert curve based on the number of images
# order = 1
# while 2 ** (2 * order) < num_images:
# order += 1
#
# # Create a Hilbert curve of the appropriate order
# hilbert_curve = HilbertCurve(order, 2)
#
# # Create a blank image to hold the arranged images
# arranged_image = Image.new('L', (image_size[0] * 2 ** order, image_size[1] * 2 ** order))
#
# # Load and arrange the images
# for i in tqdm(range(num_images)):
# # Load the image
# image_path = os.path.join(os.getcwd(), f"picture/{i}.png")
# image = Image.open(image_path).convert('L')
#
# # Determine the position of the image in the Hilbert curve
# x, y = hilbert_curve.point_from_distance(i)
#
# # Paste the image into the arranged image
# arranged_image.paste(image, (x * image_size[0], y * image_size[1]))
#
# # Display the arranged image
# # arranged_image.show()
# arranged_image.save("ip.jpg")

import os
from PIL import Image
from hilbertcurve.hilbertcurve import HilbertCurve

# Number of images
num_images = 256

# Image size (assuming all images have the same size)
original_image_size = 8192 # should be times of 16
image_size = int(original_image_size / 16)

# Determine the order of the Hilbert curve based on the number of images
order = 1
while 2 ** (2 * order) < num_images:
order += 1

# Create a Hilbert curve of the appropriate order
hilbert_curve = HilbertCurve(order, 2)

# Create a blank image to hold the arranged images
arranged_image = Image.new('L', (original_image_size, original_image_size))

# Load and arrange the images
for i in tqdm(range(num_images)):
# Load the image as grayscale
image_path = os.path.join(os.getcwd(), f"picture/{i}.png")
image = Image.open(image_path).convert('L')

# Resize the image to the desired size
image = image.resize((image_size, image_size))

# Determine the position of the image in the Hilbert curve
x, y = hilbert_curve.point_from_distance(i)

# Calculate the coordinates of the image in the arranged image
x_coord = x * image_size
y_coord = y * image_size

# Paste the image into the arranged image
arranged_image.paste(image, (x_coord, y_coord))

# Save the arranged image as a PNG file
arranged_image.save(f'ip_{original_image_size}.png')

Binary file added ip_4096.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def process(index):
path = os.path.join("picture", str(index) + ".png")
os.makedirs(os.path.dirname(path), exist_ok=True)
image.save(path, format="png")
return


def build_cache():
Expand All @@ -133,23 +134,22 @@ def build_cache():
DATA = {}
for i in tqdm(range(4096)):
for j in range(4096):

index = xy_to_hilbert(i, j, 12)
DATA[index] = (i, j)
prebuilt_hilbertCurve_4096["DATA"] = DATA
print("DUMPING FILE")
json.dump(prebuilt_hilbertCurve_4096, open("prebuilt_hilbertCurve_4096.json", "w+"))
return DATA


print("Start to load prebuild hilbert curve, usually it will take 30 second or more")
time_start = time.time()
try: # try to load cache
prebuilt_hilbertCurve_4096 = json.load(open("prebuilt_hilbertCurve_4096.json", "r"))["DATA"]
except FileNotFoundError:
prebuilt_hilbertCurve_4096 = build_cache()
print(f"Loaded prebuilt hilbert curve, take {round(time.time() - time_start, 2)} seconds")

if __name__ == '__main__':
with Pool(multiprocessing.cpu_count()) as p:
print("Start to load prebuild hilbert curve, usually it will take 30 second or more")
time_start = time.time()
try: # try to load cache
prebuilt_hilbertCurve_4096 = json.load(open("prebuilt_hilbertCurve_4096.json", "r"))["DATA"]
except FileNotFoundError:
prebuilt_hilbertCurve_4096 = build_cache()
print(f"Loaded prebuilt hilbert curve, take {round(time.time() - time_start, 2)} seconds")
with Pool(multiprocessing.cpu_count()//2) as p:
p.map(process, os.listdir("ip"))

0 comments on commit d35b2f6

Please sign in to comment.