Browse Source

wip

new-sep-loss
Michael Pilosov, PhD 9 months ago
parent
commit
04ff370bbb
  1. 1
      makefile
  2. 13
      scripts/place.sh
  3. 54
      scripts/vips_composite.py

1
makefile

@ -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

13
scripts/place.sh

@ -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

54
scripts/vips_composite.py

@ -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)
Loading…
Cancel
Save