def test_find_closest_divisor(): size = lib.find_closest_divisor((128, 128, 128), (64, 64, 64)) assert tuple(size) == (64, 64, 64) size = lib.find_closest_divisor((240, 240, 240), (64, 64, 64)) assert tuple(size) == (60, 60, 60) size = lib.find_closest_divisor((224, 224, 224), (64, 64, 64)) assert tuple(size) == (56, 56, 56) size = lib.find_closest_divisor((73, 73, 73), (64, 64, 64)) assert tuple(size) == (73, 73, 73)
def create_info_file_from_build(layer_path, layer_type, resolution, encoding): assert layer_type in ('image', 'segmentation', 'affinities') with Storage(layer_path) as storage: bounds, build_chunk_size = compute_build_bounding_box(storage) data_type, num_channels = get_build_data_type_and_shape(storage) neuroglancer_chunk_size = find_closest_divisor(build_chunk_size, closest_to=[64, 64, 64]) info = CloudVolume.create_new_info( num_channels=num_channels, layer_type=layer_type, data_type=data_type, encoding=encoding, resolution=resolution, voxel_offset=bounds.minpt.tolist(), volume_size=bounds.size3(), mesh=(layer_type == 'segmentation'), chunk_size=list(map(int, neuroglancer_chunk_size)), ) vol = CloudVolume(layer_path, mip=0, info=info).commit_info() vol = create_downsample_scales(layer_path, mip=0, ds_shape=build_chunk_size, axis='z') return vol.info
def create_volume_from_image(image, offset, layer_path, layer_type, resolution, encoding): assert layer_type in ('image', 'segmentation', 'affinities') offset = Vec(*offset) volsize = Vec(*image.shape[:3]) data_type = str(image.dtype) bounds = Bbox(offset, offset + volsize) neuroglancer_chunk_size = find_closest_divisor(image.shape[:3], closest_to=[64,64,64]) info = CloudVolume.create_new_info( num_channels=1, # Increase this number when we add more tests for RGB layer_type=layer_type, data_type=data_type, encoding=encoding, resolution=resolution, voxel_offset=bounds.minpt, volume_size=bounds.size3(), mesh=(layer_type == 'segmentation'), chunk_size=neuroglancer_chunk_size, ) vol = CloudVolume(layer_path, mip=0, info=info) vol.commit_info() vol[:,:,:] = image return vol
def upload_image(image, offset, layer_type, layer_name, encoding): lpath = 'file://{}'.format(os.path.join(layer_path, layer_name)) neuroglancer_chunk_size = find_closest_divisor(image.shape[:3], closest_to=[64,64,64]) # Jpeg encoding is lossy so it won't work vol = CloudVolume.from_numpy( image, vol_path=lpath, resolution=(1,1,1), voxel_offset=offset, chunk_size=neuroglancer_chunk_size, layer_type=layer_type, encoding=encoding, ) return vol