Skip to content
Snippets Groups Projects
Commit d31cbb27 authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

mu map dataset now return torch tensors with channel dimension

parent 40d0422e
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import cv2 as cv ...@@ -5,6 +5,7 @@ import cv2 as cv
import pandas as pd import pandas as pd
import pydicom import pydicom
import numpy as np import numpy as np
import torch
from torch.utils.data import Dataset from torch.utils.data import Dataset
from mu_map.data.prepare import headers from mu_map.data.prepare import headers
...@@ -86,12 +87,20 @@ class MuMapDataset(Dataset): ...@@ -86,12 +87,20 @@ class MuMapDataset(Dataset):
bed_contour = self.bed_contours[row["id"]] bed_contour = self.bed_contours[row["id"]]
for i in range(mu_map.shape[0]): for i in range(mu_map.shape[0]):
mu_map[i] = cv.drawContours(mu_map[i], [bed_contour], -1, 0.0, -1) mu_map[i] = cv.drawContours(mu_map[i], [bed_contour], -1, 0.0, -1)
self.mu_maps[_id] = mu_map
recon_file = os.path.join(self.dir_images, row[headers.file_recon_nac_nsc]) recon_file = os.path.join(self.dir_images, row[headers.file_recon_nac_nsc])
recon = pydicom.dcmread(recon_file).pixel_array recon = pydicom.dcmread(recon_file).pixel_array
if self.align: if self.align:
recon = align_images(recon, mu_map) recon = align_images(recon, mu_map)
mu_map = mu_map.astype(np.float32)
mu_map = torch.from_numpy(mu_map)
mu_map = mu_map.unsqueeze(dim=0)
self.mu_maps[_id] = mu_map
recon = recon.astype(np.float32)
recon = torch.from_numpy(recon)
recon = recon.unsqueeze(dim=0)
self.reconstructions[_id] = recon self.reconstructions[_id] = recon
print("Pre-loading images done!") print("Pre-loading images done!")
...@@ -194,6 +203,8 @@ if __name__ == "__main__": ...@@ -194,6 +203,8 @@ if __name__ == "__main__":
im = 0 im = 0
recon, mu_map = dataset[i] recon, mu_map = dataset[i]
recon = recon.squeeze().numpy()
mu_map = mu_map.squeeze().numpy()
print(f"{(i+1):>{len(str(len(dataset)))}}/{len(dataset)}", end="\r") print(f"{(i+1):>{len(str(len(dataset)))}}/{len(dataset)}", end="\r")
cv.imshow(wname, combine_images((recon, mu_map), (ir, im))) cv.imshow(wname, combine_images((recon, mu_map), (ir, im)))
...@@ -206,8 +217,6 @@ if __name__ == "__main__": ...@@ -206,8 +217,6 @@ if __name__ == "__main__":
to_show = combine_images((recon, mu_map), (ir, im)) to_show = combine_images((recon, mu_map), (ir, im))
cv.imshow(wname, to_show) cv.imshow(wname, to_show)
key = cv.waitKey(timeout) key = cv.waitKey(timeout)
if key == ord("n"): if key == ord("n"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment