forked from mahmoodlab/CLAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.py
More file actions
45 lines (42 loc) · 1.42 KB
/
sandbox.py
File metadata and controls
45 lines (42 loc) · 1.42 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
import h5py
from openslide import OpenSlide
import matplotlib.pyplot as plt
import numpy as np
# open in read mode
file_path = "FEATURES_DIRECTORY/h5_files/TUPAC-TR-016.h5"
file_path = "results/patches/TUPAC-TR-016.h5"
wsl_path = "data/TUPAC-TR-016.svs"
# Open the slide
slide = OpenSlide(wsl_path)
level = 1
# Get the dimensions of the slide
dimensions = slide.dimensions
print(f"Slide dimensions: {dimensions}")
level_dimensions = slide.level_dimensions[level]
print(f"Level {level} dimensions: {level_dimensions}")
patch_size = 256
with h5py.File(file_path, "r") as f:
# List all groups
print("Keys:", list(f.keys()))
# Access a dataset
data = f["coords"]
#data = f["features"]
print(data.shape, data.dtype)
print(data[:10])
n_subplots = 4
n_rows = int(np.sqrt(n_subplots))
n_cols = int(np.sqrt(n_subplots))
fig, ax = plt.subplots(n_rows, n_cols, figsize=(10, 10))
plot_count = 0
for i, coord in enumerate(data):
if i < 4:
continue
if plot_count >= n_subplots:
break
patch_image = slide.read_region(coord, level, (patch_size, patch_size))
ax[plot_count//n_cols, plot_count%n_cols].imshow(patch_image)
ax[plot_count//n_cols, plot_count%n_cols].set_xticks([])
ax[plot_count//n_cols, plot_count%n_cols].set_yticks([])
plot_count+=1
plt.savefig("results/patches/TUPAC-TR-016_patches_samples.png")
plt.show()