Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Pilosov, PhD
04ff370bbb wip 2024-02-14 04:55:42 +00:00
Michael Pilosov, PhD
90f08a5edb paths 2024-02-14 04:31:27 +00:00
4 changed files with 63 additions and 9 deletions

View File

@ -67,7 +67,6 @@ sort_lex:
sort_hsv:
python scripts/sortcolor.py -s hsv --dpi 300
clean:
rm -rf lightning_logs
rm -rf .lr_find_*.ckpt

View File

@ -9,9 +9,10 @@ INPUT_FILE="${DIR}/arrangement_grid.txt"
# OUTPUT_IMAGE="${DIR}/circle_composite_$SEED.png"
TYPE=circle
OUTPUT_IMAGE="${DIR}/${TYPE}_composite_grid.png"
DPI=100
DPI=150
CANVAS_SIZE=$((72*$DPI)) # 72 inches
CIRCLE_IMAGE="${DIR}/hsv_sorted_colors_circle.png"
CIRCLE_IMAGE="${DIR}/hsv/sorted_colors_circle.png"
KIND=umap
identify $CIRCLE_IMAGE
@ -29,15 +30,15 @@ while IFS=, read -r x y; do
ix=$(printf "%.0f" "$fx")
iy=$(printf "%.0f" "$fy")
if [[ idx -eq 42 ]]; then
CIRCLE_IMAGE="${DIR}/hsv_sorted_colors_${TYPE}.png"
CIRCLE_IMAGE="${DIR}/hsv/sorted_colors_${TYPE}.png"
else
idx_str=$(printf "%02d" "$idx")
CIRCLE_IMAGE="${DIR}/${idx_str}umap_sorted_colors_${TYPE}.png"
idx_str=$(printf "%04d" "$idx")
CIRCLE_IMAGE="${DIR}/${KIND}/${idx_str}_sorted_colors_${TYPE}.png"
# CIRCLE_IMAGE="${DIR}/hsv_sorted_colors_${TYPE}.png"
fi
# Add to the composite operations string
composite_ops="$composite_ops \( $CIRCLE_IMAGE \) -compose Over -geometry +$ix+$iy -composite"
composite_ops="$composite_ops \( $CIRCLE_IMAGE \) -resize 50% -compose Over -geometry +$ix+$iy -composite"
idx=$((idx+1))
done < $INPUT_FILE

View File

@ -38,10 +38,10 @@ DIR = "/teamspace/studios/this_studio/out_sortcolors"
prefix = ""
if KIND == "umap":
prefix = f"{SEED:04d}"
prefix = f"{SEED:04d}_"
FDIR = f"{DIR}/{KIND}"
Path(FDIR).mkdir(exist_ok=True, parents=True)
fname = f"{FDIR}/{prefix}_sorted_colors_circle.png"
fname = f"{FDIR}/{prefix}sorted_colors_circle.png"
def peano_curve(n):

54
scripts/vips_composite.py Normal file
View File

@ -0,0 +1,54 @@
import pyvips
import glob
import random
import os
import math
def create_grid_composite(
directory, k, spacing_inches, output_file="output.png", dpi=300
):
# Calculate spacing in pixels
spacing_pixels = int(spacing_inches * dpi)
# Glob for PNG images
png_files = glob.glob(os.path.join(directory, "*.png"))
# Randomly select K^2 images
selected_files = random.sample(png_files, k * k)
# Create an empty list to hold the images
images = [
pyvips.Image.new_from_file(file, access="sequential") for file in selected_files
]
# Calculate the size of the composite image
widths, heights = zip(*[image.size for image in images])
max_width = max(widths)
max_height = max(heights)
# Calculate total size of the grid including spacing
total_width = k * max_width + (k + 1) * spacing_pixels
total_height = k * max_height + (k + 1) * spacing_pixels
# Create a blank image for the composite
composite = pyvips.Image.black(total_width, total_height)
# Place images into the composite
for i, image in enumerate(images):
row = i // k
col = i % k
x = col * (max_width + spacing_pixels) + spacing_pixels
y = row * (max_height + spacing_pixels) + spacing_pixels
composite = composite.insert(image, x, y)
# Save the composite image
composite.write_to_file(output_file)
if __name__ == "__main__":
# Example usage
directory = "/teamspace/studios/this_studio/out_sortcolors/umap/" # Change to your directory path
k = 3 # For a 3x3 grid
spacing_inches = 0.5 # Half an inch between images
create_grid_composite(directory, k, spacing_inches)