-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (39 loc) · 1.67 KB
/
main.py
File metadata and controls
50 lines (39 loc) · 1.67 KB
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
44
45
46
47
48
49
50
import numpy as np
import matplotlib
matplotlib.use('TkAgg') # Du kannst dies zu 'Agg' ändern, wenn du keine GUI brauchst
import matplotlib.pyplot as plt
if __name__ == '__main__':
# Lade das Bild mit der Person vor dem Greenscreen
original = plt.imread('person_on_greenscreen.jpg')
original_npa = np.array(original)
og_shape = original_npa.shape
# Lade den Wald-Hintergrund und passe die Größe an
background = plt.imread('forest.jpg')
background_npa = np.array(background)[:og_shape[0], :og_shape[1], :og_shape[2]]
# Erstelle eine Maske für "nicht-grüne" Pixel (also die Person)
mask = ~((original_npa[:, :, 1] > 100) & # grüner Kanal stark
(original_npa[:, :, 1] > original_npa[:, :, 0] * 1.2) & # mehr als rot
(original_npa[:, :, 1] > original_npa[:, :, 2] * 1.2)) # mehr als blau
# Erstelle Bild mit schwarzem Hintergrund (nur Person sichtbar)
selected_pixels_image = np.zeros_like(original_npa)
selected_pixels_image[mask] = original_npa[mask]
# Kombiniere mit Hintergrund
combined_image = background_npa.copy()
combined_image[mask] = original_npa[mask]
# Zeige alle drei Bilder und speichere das Ergebnis
plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)
plt.title("Original Image")
plt.imshow(original_npa)
plt.axis('off')
plt.subplot(1, 3, 2)
plt.title("Selected Pixels")
plt.imshow(selected_pixels_image)
plt.axis('off')
plt.subplot(1, 3, 3)
plt.title("Combined Image")
plt.imshow(combined_image)
plt.axis('off')
plt.tight_layout()
plt.savefig("person_in_forest.png")
plt.show()