def wormhole(tensor, shape, kink, input_stride, alpha=1.0):
"""
Apply per-pixel field flow. Non-iterative.
:param Tensor tensor:
:param list[int] shape:
:param float kink: Path twistiness
:param float input_stride: Maximum pixel offset
:return: Tensor
"""
height, width, channels = shape
values = value_map(tensor, shape)
degrees = values * 360.0 * math.radians(1) * kink
# stride = values * height * input_stride
stride = height * input_stride
x_index = tf.cast(row_index(shape), tf.float32)
y_index = tf.cast(column_index(shape), tf.float32)
x_offset = (tf.cos(degrees) + 1) * stride
y_offset = (tf.sin(degrees) + 1) * stride
x = tf.cast(x_index + x_offset, tf.int32) % width
y = tf.cast(y_index + y_offset, tf.int32) % height
luminosity = tf.square(tf.reshape(values, [height, width, 1]))
out = normalize(tf.scatter_nd(offset_index(y, height, x, width), tensor * luminosity, tf.shape(tensor)))
return blend(tensor, tf.sqrt(out), alpha)
评论列表
文章目录