Пример #1
0
def downsample_and_upload(image,
                          bounds,
                          vol,
                          ds_shape,
                          mip=0,
                          axis='z',
                          skip_first=False,
                          sparse=False,
                          factor=None):
    ds_shape = min2(vol.volume_size, ds_shape[:3])
    underlying_mip = (mip + 1) if (mip + 1) in vol.available_mips else mip
    chunk_size = vol.meta.chunk_size(underlying_mip).astype(np.float32)

    if factor is None:
        factor = downsample_scales.axis_to_factor(axis)
    factors = downsample_scales.compute_factors(ds_shape, factor, chunk_size)

    if len(factors) == 0:
        print(
            "No factors generated. Image Shape: {}, Downsample Shape: {}, Volume Shape: {}, Bounds: {}"
            .format(image.shape, ds_shape, vol.volume_size, bounds))

    vol.mip = mip
    if not skip_first:
        vol[bounds.to_slices()] = image

    if len(factors) == 0:
        return

    num_mips = len(factors)

    mips = []
    if vol.layer_type == 'image':
        mips = tinybrain.downsample_with_averaging(image,
                                                   factors[0],
                                                   num_mips=num_mips)
    elif vol.layer_type == 'segmentation':
        mips = tinybrain.downsample_segmentation(image,
                                                 factors[0],
                                                 num_mips=num_mips,
                                                 sparse=sparse)
    else:
        mips = tinybrain.downsample_with_striding(image,
                                                  factors[0],
                                                  num_mips=num_mips)

    new_bounds = bounds.clone()

    for factor3 in factors:
        vol.mip += 1
        new_bounds //= factor3
        mipped = mips.pop(0)
        new_bounds.maxpt = new_bounds.minpt + Vec(*mipped.shape[:3])
        vol[new_bounds] = mipped
Пример #2
0
    def ds_shape(mip, chunk_size=None, factor=None):
        if chunk_size:
            shape = Vec(*chunk_size)
        else:
            shape = vol.meta.chunk_size(mip)[:3]

        if factor is None:
            factor = downsample_scales.axis_to_factor(axis)

        shape.x *= factor[0]**num_mips
        shape.y *= factor[1]**num_mips
        shape.z *= factor[2]**num_mips
        return shape