Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
# this routine reads in many image files which are 128 pixels high | |
# and finds the lowest and highest non-black pixels across all images | |
import sys | |
from PIL import Image | |
from control_toys.data import fast_scandir | |
from tqdm import tqdm | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print(f"Usage: {sys.argv[0]} <image-dirs>") | |
sys.exit(1) | |
img_dirs = sys.argv[1:] | |
img_files = [] | |
for imgdir in img_dirs: | |
i_subdirs, imfile = fast_scandir(imgdir, ['png', 'jpg', 'jpeg']) | |
if imfile != []: img_files = img_files + imfile | |
# remove any files with the 'transpose' in the name | |
img_files = [f for f in img_files if 'transpose' not in f] | |
if len(img_files) == 0: | |
print(f"No image files found in {img_dirs}") | |
sys.exit(1) | |
min_note = 128 | |
max_note = 0 | |
for img_file in tqdm(img_files): | |
img = Image.open(img_file) | |
img = img.convert('L') | |
for y in range(img.size[-1]): | |
for x in range(img.size[0]): | |
val = img.getpixel((x,y)) | |
if val > 0: | |
if y < min_note: min_note = y | |
if y > max_note: max_note = y | |
break | |
print(f"min_note = {min_note}, max_note = {max_note}") | |
transpose_max = 12 | |
print(f"So with transpostion of +/-{transpose_max}, the range is", min_note-transpose_max, "to", max_note+transpose_max) | |
sys.exit(0) |