Add files via upload

This commit is contained in:
David Rotermund 2023-07-12 23:58:19 +02:00 committed by GitHub
parent 7799b9910a
commit dd0b3c580f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 0 deletions

View file

@ -66,6 +66,7 @@ while int(master_mask.sum()) > 0:
).astype(dtype=np.float32)
else:
coords = contour.astype(dtype=np.float32)
# Make a mask out of the polygon
mask = skimage.draw.polygon2mask(scale.shape, coords)
assert mask is not None

54
inspection.py Normal file
View file

@ -0,0 +1,54 @@
import numpy as np
import torch
import matplotlib.pyplot as plt
import skimage
from scipy.stats import skew
filename: str = "example_data_crop"
torch_device: torch.device = torch.device(
"cuda:0" if torch.cuda.is_available() else "cpu"
)
print("Load data")
input = np.load(filename + str("_decorrelated.npy"))
data = torch.tensor(input, device=torch_device)
del input
print("loading done")
stored_contours = np.load("cells.npy", allow_pickle=True)
to_plot = torch.zeros(
(int(data.shape[0]), int(stored_contours.shape[0])),
device=torch_device,
dtype=torch.float32,
)
for id in range(0, stored_contours.shape[0]):
mask = torch.tensor(
skimage.draw.polygon2mask(
(int(data.shape[1]), int(data.shape[2])), stored_contours[id]
),
device=torch_device,
dtype=torch.float32,
)
ts = (data * mask.unsqueeze(0)).nan_to_num(nan=0.0).sum(dim=(-2, -1)) / mask.sum()
to_plot[:, id] = ts
skew_value = skew(to_plot.cpu().numpy(), axis=0)
skew_idx = np.flip(skew_value.argsort())
skew_value = skew_value[skew_idx]
to_plot_np = to_plot.cpu().numpy()
to_plot_np = to_plot_np[:, skew_idx]
plt.plot(to_plot[:, 0:5].cpu())
plt.show()
block_size: int = 8
# print(to_plot.shape[1] // block_size)
for i in range(0, 4 * 8):
plt.subplot(8, 4, i + 1)
plt.plot(to_plot[:, i * block_size : (i + 1) * block_size].cpu())
plt.show()