MCPcopy Create free account
hub / github.com/KerenLab/CellSighter / load_samples

Function load_samples

data/utils.py:92–137  ·  view source on GitHub ↗

Args: images_dir: path to the images cells_dir: path to the segmentation cells2labels_dir: path to mapping cells to labels images_names: names of images to load from the images_dir crop_size: the size of the crop of the cell channels: indices of

(images_dir, cells_dir, cells2labels_dir, images_names, crop_size, to_pad=False, channels=None)

Source from the content-addressed store, hash-verified

90
91
92def load_samples(images_dir, cells_dir, cells2labels_dir, images_names, crop_size, to_pad=False, channels=None):
93 """
94
95 Args:
96 images_dir: path to the images
97 cells_dir: path to the segmentation
98 cells2labels_dir: path to mapping cells to labels
99 images_names: names of images to load from the images_dir
100 crop_size: the size of the crop of the cell
101 channels: indices of channels to load from each image
102 Returns:
103 Array of CellCrop per cell in the dataset
104 """
105 images_dir = Path(images_dir)
106 cells_dir = Path(cells_dir)
107 cells2labels_dir = Path(cells2labels_dir)
108 crops = []
109 for image_id in images_names:
110 image_path = glob.glob(str(images_dir / f"{image_id}.npz")) + \
111 glob.glob(str(images_dir / f"{image_id}.tiff"))
112 cells_path = glob.glob(str(cells_dir / f"{image_id}.npz")) + \
113 glob.glob(str(cells_dir / f"{image_id}.tiff"))
114 cells2labels_path = glob.glob(str(cells2labels_dir / f"{image_id}.npz")) + \
115 glob.glob(str(cells2labels_dir / f"{image_id}.txt"))
116 image, cells, cl2lbl = load_image(image_path=image_path[0],
117 cells_path=cells_path[0],
118 cells2labels_path=cells2labels_path[0],
119 channels=channels,
120 to_pad=to_pad,
121 crop_size=crop_size)
122
123 objs = ndimage.find_objects(cells)
124 for cell_id, obj in enumerate(objs, 1):
125 try:
126 slices = create_slices(obj, (crop_size, crop_size), cells.shape)
127 label = cl2lbl[cell_id]
128 crops.append(
129 CellCrop(cell_id=cell_id,
130 image_id=image_id,
131 label=label,
132 slices=slices,
133 cells=cells,
134 image=image))
135 except Exception as e:
136 pass
137 return np.array(crops)
138
139
140def load_crops(root_dir,

Callers 1

load_cropsFunction · 0.85

Calls 3

CellCropClass · 0.90
load_imageFunction · 0.85
create_slicesFunction · 0.85

Tested by

no test coverage detected