-
Notifications
You must be signed in to change notification settings - Fork 22
Description
I ran the script by the data of myself. the N5 parameter is {"compression":{"type":"gzip","useZlib":false,"level":-1},"pixelResolution":[0.18026115154068303,0.18026115154068303,0.9994],"downsamplingFactors":[1,1,1],"blockSize":[64,64,5],"dataType":"uint8","dimensions":[3904,3884,14]}, there alway is an error in the _method.py, line 80,
def _count_reduce_items(arr, axis, keepdims=False, where=True):
# fast-path for the default case
if where is True:
# no boolean mask given, calculate items according to axis
if axis is None:
axis = tuple(range(arr.ndim))
elif not isinstance(axis, tuple):
axis = (axis,)
items = 1
for ax in axis: #edit by gaoxinwei
items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
items = nt.intp(items)
the axis is 0, so in the ax in axis, it stopped.
Could you help me the find the reason? thank you ~
the main script as follow:
import numpy as np
import zarr, tifffile
from bigstream.align import alignment_pipeline
from bigstream.transform import apply_transform
file paths to tutorial data
replace the capitalized text below with the path to your copy of the bigstream repository
fix_path = 'D:/bigatream/r1.n5'
mov_path = 'D:/bigatream/r2.n5'
create Zarr file objects
fix_zarr = zarr.open(store=zarr.N5Store(fix_path), mode='r')
mov_zarr = zarr.open(store=zarr.N5Store(mov_path), mode='r')
get pointers to the low res scale level
still just pointers, no data loaded into memory yet
fix_lowres = fix_zarr['/lowres']
mov_lowres = mov_zarr['/lowres']
we need the voxel spacings for the low res data sets
we can compute them from the low res data set metadata
fix_meta = fix_lowres.attrs.asdict()
mov_meta = mov_lowres.attrs.asdict()
fix_lowres_spacing = np.array(fix_meta['pixelResolution']) * fix_meta['downsamplingFactors']
mov_lowres_spacing = np.array(mov_meta['pixelResolution']) * mov_meta['downsamplingFactors']
fix_lowres_spacing = fix_lowres_spacing[::-1] # put in zyx order to be consistent with image data
mov_lowres_spacing = mov_lowres_spacing[::-1]
read small image data into memory as numpy arrays
fix_lowres_data = fix_lowres[...]
mov_lowres_data = mov_lowres[...]
sanity check: print the voxel spacings and lowres dataset shapes
print(fix_lowres_spacing, mov_lowres_spacing)
print(fix_lowres_data.shape, mov_lowres_data.shape)
get pointers to the high res scale level
fix_highres = fix_zarr['/highres']
mov_highres = mov_zarr['/highres']
we need the voxel spacings for the high res data sets
we can compute them from the high res data set metadata
fix_meta = fix_highres.attrs.asdict()
mov_meta = mov_highres.attrs.asdict()
fix_highres_spacing = np.array(fix_meta['pixelResolution']) * fix_meta['downsamplingFactors']
mov_highres_spacing = np.array(mov_meta['pixelResolution']) * mov_meta['downsamplingFactors']
fix_highres_spacing = fix_highres_spacing[::-1]
mov_highres_spacing = mov_highres_spacing[::-1]
sanity check: print the voxel spacings and lowres dataset shapes
print(fix_highres_spacing, mov_highres_spacing)
print(fix_highres.shape, mov_highres.shape)
define arguments for the feature point and ransac stage (you'll understand these later)
ransac_kwargs = {'blob_sizes':[6, 20]}
#ransac_kwargs = {'blob_sizes':[6, 20]}
define arguments for the gradient descent stage (you'll understand these later)
affine_kwargs = {
'shrink_factors':(2,),
'smooth_sigmas':(2.5,),
'optimizer_args':{
'learningRate':0.25,
'minStep':0.,
'numberOfIterations':400,
},
}
define the alignment steps
steps = [('ransac', ransac_kwargs), ('affine', affine_kwargs)]
execute the alignment
affine = alignment_pipeline(
fix_lowres_data, mov_lowres_data,
fix_lowres_spacing, mov_lowres_spacing,
steps,
)
resample the moving image data using the transform you found
aligned = apply_transform(
fix_lowres_data, mov_lowres_data,
fix_lowres_spacing, mov_lowres_spacing,
transform_list=[affine,],
)
write results
np.savetxt('./affine.mat', affine)
tifffile.imsave('./affine_lowres.tiff', aligned)
load precomputed result (handy to use later if you've already run the cell)
affine = np.loadtxt('./affine.mat')