-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_random_cosmic_image.py
More file actions
58 lines (45 loc) · 2.22 KB
/
Copy pathshow_random_cosmic_image.py
File metadata and controls
58 lines (45 loc) · 2.22 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
51
52
53
54
55
56
57
58
import os
import glob
import random
import numpy as np
import matplotlib.pyplot as plt
def show_random_image(dataset_dir="cosmic_dataset"):
# Nur im test_data Ordner suchen
test_dir = os.path.join(dataset_dir, "test_data")
search_pattern = os.path.join(test_dir, "**", "*.npy")
all_npy_files = glob.glob(search_pattern, recursive=True)
# sky.npy aussortieren
npy_files = [f for f in all_npy_files if os.path.basename(f) != 'sky.npy']
if not npy_files:
print(f"Keine passenden .npy Dateien in {test_dir} gefunden.")
return
random_file = random.choice(npy_files)
print(f"Lade Datei: {random_file}")
# Gemäß cosmic_utils.py besteht das Array aus [Bild, Maske, Ignore]
data = np.load(random_file)
if data.ndim == 3 and data.shape[0] >= 2:
img = data[0].astype(np.float32)
mask = data[1].astype(np.float32)
ignore_mask = data[2].astype(np.float32) if data.shape[0] >= 3 else np.zeros_like(img)
print(f"Original shape: {data.shape} -> Extracted image shape: {img.shape}")
fig, axes = plt.subplots(1, 3, figsize=(18, 6))
# Bild (Lineare Skalierung mit Perzentilen, um das Hintergrundrauschen nicht künstlich zu verstärken)
# Wir berechnen das 1. und 99.5. Perzentil für einen guten visuellen Kontrast
vmin, vmax = np.percentile(img, [1, 99.5])
im1 = axes[0].imshow(img, cmap='gray', origin='lower', vmin=vmin, vmax=vmax)
axes[0].set_title(f"Image (data[0])\n{os.path.basename(random_file)}")
fig.colorbar(im1, ax=axes[0], label='Pixel Value')
# Cosmic Ray Maske
im2 = axes[1].imshow(mask, cmap='gray', origin='lower')
axes[1].set_title(f"Cosmic Ray Mask (data[1])")
fig.colorbar(im2, ax=axes[1], label='CR Mask Value')
# Ignore Maske
im3 = axes[2].imshow(ignore_mask, cmap='gray', origin='lower')
axes[2].set_title(f"Ignore Mask (data[2])\n(Defekte Pixel/Hintergrund)")
fig.colorbar(im3, ax=axes[2], label='Ignore Mask Value')
plt.tight_layout()
plt.show()
else:
print(f"Unerwartetes Format. Shape: {data.shape}")
if __name__ == "__main__":
show_random_image()