-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (36 loc) · 1.53 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os, sys
import random
from crop_and_append import getthumbnail
from matrixsize import get_size
#TODO: Let user choose which path as root filder
#config
ROOTPATH_PRESET = "C:/Users/zhao_/Pictures/2023"
ALLOWED_MATRIXSIZES = [1,2,3,4,5,6]
RAW_FILE_NEEDED_TO_PASS = ".NEF"
CAMERA_IMAGE_SIZE = (6000,4000)
PREFIX="thumbnail-"
ROOTPATH = sys.argv[1] if len(sys.argv) > 1 else ROOTPATH_PRESET
for root, dirs, files in os.walk(ROOTPATH, topdown=False):
if files:
imagePathList = []
for name in files:
if RAW_FILE_NEEDED_TO_PASS in name:
pass
else:
imagePathList.append(os.path.join(root, name))
#find the right matrix size.
(matrixSize, needSample) = get_size(ALLOWED_MATRIXSIZES, len(imagePathList))
print(matrixSize, needSample)
#if imagePathList contains too many images, randomly choose some out of them.
if needSample:
imagePathList = random.sample(imagePathList, ALLOWED_MATRIXSIZES[-1]**2)
outpath=os.path.abspath(os.path.join(root,
os.pardir,
PREFIX + str(os.path.basename(root))))
print(imagePathList)
thumbnail_size= (int(6000/matrixSize),int(4000/matrixSize))
getthumbnail(imagePathList=imagePathList,
outPath=outpath,
thumbnailSize=thumbnail_size,
matrixW=matrixSize,
matrixH=matrixSize)