-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_header_template.py
34 lines (27 loc) · 1.16 KB
/
generate_header_template.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
from pathlib import Path
from PIL import Image, ImageFilter
MODEL_DIR = Path("E:\\projects\\modular\\kicad\\protorack-kicad\\3dmodels\\Protorack.3dshapes")
MODELS = (
"AudioJacks/QingPu_WQP-PJ612A",
"AudioJacks/QingPu_WQP-WQP518MA-BM",
"Switches/E-Switch_EG2201B/E-Switch_EG2201B",
"PushButtons/E-Switch_TL1105T/E-Switch_TL1105T",
"Connectors/Amphenol_12402012E212A/Amphenol_12402012E212A",
"Connectors/Amphenol_UE27AC/Amphenol_UE27AC",
"Potentiometers/Alpha_RD901F-40/Alpha_RD901F-40-15F",
"Potentiometers/Alpha_RV16AF/Alpha_RV16AF-10-17K",
)
OUTPUT_SIZE = (len(MODELS) * 900, 900)
combined = Image.new("RGB", OUTPUT_SIZE)
mask = Image.new("1", OUTPUT_SIZE)
for i, model in enumerate(MODELS):
image = Image.open(MODEL_DIR / (model + ".jpg"))
cropped = image.crop((50, 50, 950, 950))
combined.paste(cropped, (900 * i, 0))
grayscale = cropped.convert("L")
threshold = grayscale.point(lambda v: 255 if v > 44 else 0)
blurred = threshold.filter(ImageFilter.GaussianBlur(15))
mono = blurred.point(lambda v: 255 if v > 5 else 0)
mask.paste(mono, (900 * i, 0))
combined.save("template.png")
mask.save("template_mask.png")