Skip to content

Commit

Permalink
BUG FIX: PeregrineHDF5Reader now properly flips images across the X a…
Browse files Browse the repository at this point in the history
…xis. (#1103)

Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers authored Oct 10, 2024
1 parent edf590d commit 51372c2
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@ def _read_scan_datasets(self, h5_file_reader: h5py.File, data_structure: nx.Data
vertices, edges, tot = scan_data_result.value

# Flip vertices across the X axis
flipped_vertices = self._flip_vertices_across_x_axis(vertices)
# vertices = self._flip_vertices_across_x_axis(vertices)

# Copy the vertices into the edge geometry
v_end = vertex_tuple_offset + flipped_vertices.shape[0]
vertex_list_view[vertex_tuple_offset:v_end, :] = flipped_vertices
v_end = vertex_tuple_offset + vertices.shape[0]
vertex_list_view[vertex_tuple_offset:v_end, :] = vertices

# Update edges values to match the actual vertices indices
edges += vertex_tuple_offset
Expand All @@ -1078,13 +1078,13 @@ def _read_scan_datasets(self, h5_file_reader: h5py.File, data_structure: nx.Data

return Result()

def _flip_slice_across_x_axis(self, slice_arr: np.ndarray):
def _flip_slice_across_x_axis(self, image_arr: np.ndarray):
# Flip slices across the X axis (this is necessary to have the images read in the real coordinate system, not the image coordinate system)
if slice_arr.ndim == 2:
slice_arr[:] = np.flip(slice_arr[:], axis=1)
elif slice_arr.ndim == 3:
for z in range(slice_arr.shape[0]):
slice_arr[:, :, z] = np.flip(slice_arr[:, :, z], axis=1)
if image_arr.ndim == 2:
image_arr[:] = np.flip(image_arr[:], axis=0)
elif image_arr.ndim == 3:
for z in range(image_arr.shape[0]):
image_arr[z, :, :] = np.flip(image_arr[z, :, :], axis=0)
else:
raise ValueError("Input array must be either 2D or 3D.")

Expand Down

0 comments on commit 51372c2

Please sign in to comment.