示例#1
0
                                                  ("HDF5", "*.h5")])
if file_path.endswith('npz'):
    kwarg = {'fieldname': 'amp'}
else:
    kwarg = {}

obj, extension = util.load_file(file_path, **kwarg)
if extension == '.h5':
    comment = comment + '_mode'

if phasing_shape is None:
    phasing_shape = obj.shape

if upsampling_factor > 1:
    obj, _ = fu.upsample(array=obj,
                         upsampling_factor=upsampling_factor,
                         debugging=debug)
    print(f'Upsampled object shape = {obj.shape}')
    voxel_size = [vox / upsampling_factor for vox in voxel_size]
    comment += f'_ups{upsampling_factor}'

######################
# define the support #
######################
obj = abs(obj)
min_obj = obj[np.nonzero(obj)].min()
obj = obj / min_obj  # normalize to the non-zero min to avoid dividing by small numbers
obj[obj == 0] = min_offset  # avoid dividing by 0
support = np.zeros(obj.shape)
support[obj >= isosurface_threshold * obj.max()] = 1
support[support == 0] = min_offset
示例#2
0
                                convert_grey=True,
                                cmap='gray',
                                debug=False)
else:
    obj, _ = util.load_file(file_path)

obj = abs(obj)
ndim = obj.ndim
if isinstance(voxel_size, Real):
    voxel_size = (voxel_size, ) * ndim

print(f'Object shape = {obj.shape}, voxel size = {voxel_size}')
if upsampling_factor > 1:
    obj, voxel_size = fu.upsample(array=obj,
                                  upsampling_factor=upsampling_factor,
                                  voxelsizes=voxel_size,
                                  title='modulus',
                                  debugging=debug)
    print(
        f'Upsampled object shape = {obj.shape}, upsampled voxel size = {voxel_size}'
    )
else:
    valid.valid_container(voxel_size,
                          container_types=(list, tuple, np.ndarray),
                          length=ndim,
                          item_types=Real,
                          min_excluded=0,
                          name='angular_profile')

#########################
# check some parameters #
示例#3
0
plt.ion()
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(initialdir=datadir, filetypes=[("NPZ", "*.npz")])
npzfile = np.load(file_path)
amp = npzfile['amp']
amp = amp / amp.max()
nz, ny, nx = amp.shape
print("Initial data size: (", nz, ',', ny, ',', nx, ')')
strain = npzfile['strain']

#################
# upsample data #
#################
if upsampling_factor > 1:
    amp, voxel_size = fu.upsample(array=amp, upsampling_factor=upsampling_factor, voxelsizes=voxel_size,
                                  debugging=debug)
    strain, _ = fu.upsample(array=strain, upsampling_factor=upsampling_factor, voxelsizes=voxel_size,
                            debugging=debug)
    nz, ny, nx = amp.shape
    print("Upsampled data size: (", nz, ',', ny, ',', nx, ')')
    print("New voxel sizes: ", voxel_size)

#####################################################################
# Use marching cubes to obtain the surface mesh of these ellipsoids #
#####################################################################
vertices_old, faces, _, _ = measure.marching_cubes_lewiner(amp, level=support_threshold, step_size=1)
nb_vertices = vertices_old.shape[0]
# vertices is a list of 3d coordinates of all vertices points
# faces is a list of facets defined by the indices of 3 vertices

# from scipy.io import savemat
示例#4
0
plt.ion()
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(initialdir=datadir, filetypes=[("NPZ", "*.npz")])
npzfile = np.load(file_path)
amp = npzfile['amp']
amp = amp / amp.max()
nz, ny, nx = amp.shape
print("Initial data size: (", nz, ',', ny, ',', nx, ')')
strain = npzfile['strain']

#################
# upsample data #
#################
if upsampling_factor > 1:
    amp, _ = fu.upsample(array=amp, upsampling_factor=upsampling_factor, voxelsizes=voxel_size,
                         title='modulus', debugging=debug)
    strain, voxel_size = fu.upsample(array=strain, upsampling_factor=upsampling_factor, voxelsizes=voxel_size,
                                     title='strain', debugging=debug)
    nz, ny, nx = amp.shape
    print("Upsampled data size: (", nz, ',', ny, ',', nx, ')')
    print("New voxel sizes: ", voxel_size)

#####################################################################
# Use marching cubes to obtain the surface mesh of these ellipsoids #
#####################################################################
vertices_old, faces, _, _ = measure.marching_cubes_lewiner(amp, level=support_threshold, allow_degenerate=False,
                                                           step_size=1)
# vertices_old is a list of 3d coordinates of all vertices points
# faces is a list of facets defined by the indices of 3 vertices_old

# from scipy.io import savemat