Skip to content

Commit

Permalink
Handle affinity map with more than 3 channels
Browse files Browse the repository at this point in the history
By default only use the first 3 channels, which are assumed to be the
nearest neighbour affinities.
  • Loading branch information
ranlu committed Sep 11, 2024
1 parent 7989230 commit 278ff58
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/cut_chunk_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def convert_and_scale_integer_data(data, dtype_out):

def cut_data(data, start_coord, end_coord, padding):
bb = tuple(slice(start_coord[i], end_coord[i]) for i in range(3))
global_param = cu.read_inputs(os.environ['PARAM_JSON'])
if data.shape[3] == 1:
if data.dtype == 'float32':
pmap = numpy.squeeze(data[bb])
Expand All @@ -50,7 +51,6 @@ def cut_data(data, start_coord, end_coord, padding):
elif data.shape[3] == 3:
return pad_data(convert_and_scale_integer_data(data[bb+(slice(0,3),)], "float32"), padding)
elif data.shape[3] == 4: #0-2 affinity, 3 myelin
global_param = cu.read_inputs(os.environ['PARAM_JSON'])
th = global_param.get('MYELIN_THRESHOLD', 0.3)
print("threshold myelin mask at {}".format(th))
cutout = data[bb+(slice(0,4),)]
Expand All @@ -62,8 +62,10 @@ def cut_data(data, start_coord, end_coord, padding):
tmp[mask] = 0
#affinity[:,:,:,i] = numpy.multiply(affinity[:,:,:,i]*(1-myelin))
return pad_data(affinity, padding)

else:
aff_channels = global_param.get('AFF_CHANNELS', 3)
if data.shape[3] >= aff_channels:
return pad_data(convert_and_scale_integer_data(data[bb+(slice(0,aff_channels),)], "float32"), padding)
raise RuntimeError("encountered array of dimension " + str(len(data.shape)))


0 comments on commit 278ff58

Please sign in to comment.