Skip to content

Commit

Permalink
fix: z-position mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
WenChentao committed Nov 24, 2023
1 parent b5fdfd7 commit 501352d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 98 deletions.
12 changes: 6 additions & 6 deletions CellTracker/coord_image_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def extract_regions(segmentation: ndarray):
self.coord_vol1 = Coordinates(np.asarray(coord_vol1), interpolation_factor, self.voxel_size, dtype="raw")
coords_real_path = self.results_folder / TRACK_RESULTS / COORDS_REAL
coords_real_path.mkdir(parents=True, exist_ok=True)
np.save(str(coords_real_path / "coords0001.npy"), np.asarray(coord_vol1))
np.save(str(coords_real_path / "coords000001.npy"), self.coord_vol1.real)

def move_cells_in_3d_image(self, movements_nx3: ndarray = None, cells_missed: Set[int] = None):
"""
Expand Down Expand Up @@ -404,7 +404,7 @@ def get_cells_on_boundary(self, coordinates_real_nx3: ndarray, ensemble: bool, b
return boundary_ids

def accurate_correction(self, t: int, grid: Tuple[int, int, int], coords: Coordinates, ensemble: bool,
max_repetition: int = 20):
max_repetition: int = 20, format = "prob%06d.npy"):
"""
Correct center positions of cells based on the probability map.
Expand All @@ -428,7 +428,7 @@ def accurate_correction(self, t: int, grid: Tuple[int, int, int], coords: Coordi
corrected_labels_image : ndarray
The corrected labels image.
"""
prob_map = np.load(str(self.results_folder / SEG / ("prob%05d.npy" % t)))
prob_map = np.load(str(self.results_folder / SEG / (format % t)))
prob_map = np.repeat(np.repeat(np.repeat(prob_map, grid[1], axis=0), grid[2], axis=1), grid[0], axis=2)
if prob_map.shape != self.proofed_segmentation.shape:
x_lim, y_lim, z_lim = self.proofed_segmentation.shape
Expand Down Expand Up @@ -509,15 +509,15 @@ def save_tracking_results(self, coords: Coordinates, corrected_labels_image: nda
images_path : str
The path to the directory containing the raw images.
"""
np.save(str(self.results_folder / TRACK_RESULTS / COORDS_REAL / ("coords%05d.npy" % t2)), coords.real)
np.save(str(self.results_folder / TRACK_RESULTS / COORDS_REAL / ("coords%06d.npy" % t2)), coords.real)
save_tracked_labels(self.results_folder, corrected_labels_image, t2, self.use_8_bit)
self.save_merged_labels(corrected_labels_image, images_path, t2)

confirmed_coord_t1 = np.load(
str(self.results_folder / TRACK_RESULTS / COORDS_REAL / f"coords{str(t1).zfill(4)}.npy"))
str(self.results_folder / TRACK_RESULTS / COORDS_REAL / f"coords{str(t1).zfill(6)}.npy"))
segmented_pos_t2 = tracker._get_segmented_pos(t2)
fig = plot_prgls_prediction(confirmed_coord_t1, segmented_pos_t2.real, coords.real, t1, t2)
fig.savefig(self.results_folder / TRACK_RESULTS / "figure" / f"matching_{str(t2).zfill(4)}.png",
fig.savefig(self.results_folder / TRACK_RESULTS / "figure" / f"matching_{str(t2).zfill(6)}.png",
facecolor='white')
plt.close()

Expand Down
4 changes: 2 additions & 2 deletions CellTracker/stardistwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def predict_and_save(images_path: str, model: StarDist3DCustom, results_folder:
break
(labels, details), prob_map = model.predict_instances(x)
# Save predicted instance coordinates as numpy arrays
coords_filepath = str(_seg_path / f"coords{str(t).zfill(4)}.npy")
prob_filepath = str(_seg_path / f"prob{str(t).zfill(4)}.npy")
coords_filepath = str(_seg_path / f"coords{str(t).zfill(6)}.npy")
prob_filepath = str(_seg_path / f"prob{str(t).zfill(6)}.npy")
np.save(coords_filepath, details["points"][:, [1, 2, 0]])
np.save(prob_filepath, prob_map.transpose((1, 2, 0)))
if t == smallest_number:
Expand Down
4 changes: 2 additions & 2 deletions CellTracker/trackerlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def predict_cell_positions_ensemble(self, skipped_volumes: List[int], t2: int, c
for t1 in get_volumes_list(current_vol=t2, skip_volumes=skipped_volumes, sampling_number=sampling_number,
adjacent=adjacent):
loaded_coord_t1 = np.load(
str(self.results_dir / TRACK_RESULTS / COORDS_REAL / f"coords{str(t1).zfill(4)}.npy"))
str(self.results_dir / TRACK_RESULTS / COORDS_REAL / f"coords{str(t1).zfill(6)}.npy"))
loaded_coord_t1_ = Coordinates(loaded_coord_t1, coord_t1.interpolation_factor, coord_t1.voxel_size,
dtype="real")
coord_prgls.append(self.predict_cell_positions(t1=t1, t2=t2, confirmed_coord_t1=loaded_coord_t1_, beta=beta,
Expand Down Expand Up @@ -146,7 +146,7 @@ def _get_segmented_pos(self, t: int) -> Coordinates:
interp_factor = self.proofed_coords_vol1.interpolation_factor
voxel_size = self.proofed_coords_vol1.voxel_size

pos = Coordinates(np.load(str(self.results_dir / SEG / f"coords{str(t).zfill(4)}.npy")),
pos = Coordinates(np.load(str(self.results_dir / SEG / f"coords{str(t).zfill(6)}.npy")),
interpolation_factor=interp_factor, voxel_size=voxel_size, dtype="raw")
return pos

Expand Down
124 changes: 36 additions & 88 deletions Examples/use_stardist/track_stardist_single_mode.ipynb

Large diffs are not rendered by default.

0 comments on commit 501352d

Please sign in to comment.