Exemplo n.º 1
0
def _build_spread_kernel(how, is_image):
    """Build a spreading kernel for a given composite operator"""
    validate_operator(how, is_image=True)
    op = composite_op_lookup[how + ("" if is_image else "_arr")]

    @ngjit
    def kernel(arr, mask, out):
        M, N = arr.shape
        w = mask.shape[0]
        for y in range(M):
            for x in range(N):
                el = arr[y, x]
                # Skip if data is transparent
                process_image = is_image and (
                    (int(el) >> 24) & 255)  # Transparent pixel
                process_array = (not is_image) and (not np.isnan(el))
                if process_image or process_array:
                    for i in range(w):
                        for j in range(w):
                            # Skip if mask is False at this value
                            if mask[i, j]:
                                if el == 0:
                                    result = out[i + y, j + x]
                                if out[i + y, j + x] == 0:
                                    result = el
                                else:
                                    result = op(el, out[i + y, j + x])
                                out[i + y, j + x] = result

    return kernel
Exemplo n.º 2
0
def _build_float_kernel(how, mask_size):
    """Build a spreading kernel for a given composite operator"""
    validate_operator(how, is_image=False)
    op = composite_op_lookup[how + "_arr"]

    @ngjit
    def stencilled(arr, mask, out):
        M, N = arr.shape
        for y in range(M):
            for x in range(N):
                el = arr[y, x]
                for i in range(mask_size):
                    for j in range(mask_size):
                        if mask[i, j]:
                            if np.isnan(el):
                                result = out[i + y, j + x]
                            elif np.isnan(out[i + y, j + x]):
                                result = el
                            else:
                                result = op(el, out[i + y, j + x])
                            out[i + y, j + x] = result

    return stencilled