Skip to content

Commit

Permalink
fix AffinityMap destroy voxel size and voxel offset metadata bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xiuliren committed Apr 8, 2024
1 parent 0aee467 commit b294d73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
19 changes: 16 additions & 3 deletions chunkflow/chunk/affinity_map/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ class AffinityMap(Chunk):
"""
a chunk of affinity map. It has x,y,z three channels with single precision.
"""
def __init__(self, array,
def __init__(self, array: np.ndarray,
voxel_offset: Cartesian=None,
voxel_size: Cartesian=None ):
voxel_size: Cartesian=None,
layer_type: str = None):
assert isinstance(array, np.ndarray)
assert array.ndim == 4
assert np.issubdtype(array.dtype, np.float32)
assert array.shape[0] == 3
super().__init__(array, voxel_offset=voxel_offset, voxel_size=voxel_size)
super().__init__(array,
voxel_offset=voxel_offset,
voxel_size=voxel_size,
layer_type=layer_type)

@classmethod
def from_chunk(cls, chk: Chunk):
assert isinstance(chk, Chunk)
return cls(chk.array,
voxel_offset = chk.voxel_offset,
voxel_size = chk.voxel_size,
layer_type = chk.layer_type)

def quantize(self, mode: str='xy'):
"""transform affinity map to gray scale image
Expand Down
1 change: 0 additions & 1 deletion chunkflow/chunk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ def from_h5(cls, file_name: str,
arr = arr.astype('float64')

print(f'new chunk voxel offset: {cutout_start}')

return cls(arr, voxel_offset=cutout_start, voxel_size=voxel_size, layer_type=layer_type)

def to_h5(self, file_name: str, with_offset: bool=True,
Expand Down
2 changes: 1 addition & 1 deletion chunkflow/flow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ def quantize(tasks, input_chunk_name: str, output_chunk_name: str, mode: str):
if task is not None:
chk = task[input_chunk_name]
if chk.is_affinity_map:
chk = AffinityMap(chk)
chk = AffinityMap.from_chunk(chk)
quantized_image = chk.quantize(mode=mode)
elif chk.is_probability_map:
quantized_image = (chk * 255.)
Expand Down

0 comments on commit b294d73

Please sign in to comment.