Skip to content

Instantly share code, notes, and snippets.

@blzq
blzq / tf_gaussian_blur.py
Last active October 2, 2023 12:37
TensorFlow (Python) implementation of Gaussian blur of image with variable input kernel size and sigma
def gaussian_blur(img, kernel_size=11, sigma=5):
def gauss_kernel(channels, kernel_size, sigma):
ax = tf.range(-kernel_size // 2 + 1.0, kernel_size // 2 + 1.0)
xx, yy = tf.meshgrid(ax, ax)
kernel = tf.exp(-(xx ** 2 + yy ** 2) / (2.0 * sigma ** 2))
kernel = kernel / tf.reduce_sum(kernel)
kernel = tf.tile(kernel[..., tf.newaxis], [1, 1, channels])
return kernel
gaussian_kernel = gauss_kernel(tf.shape(img)[-1], kernel_size, sigma)
@blzq
blzq / tf_add_axis_angle_rotations.py
Last active August 31, 2018 11:05
TensorFlow (Python) code to add two axis-angle rotation vectors
def add_axis_angle_rotations(rv1, rv2):
""" Given angle*axis rotation vectors a*l and b*m, result angle*axis: c*n
cos(c/2) = cos(a/2)cos(b/2) - sin(a/2)sin(b/2) (l . m)
sin(c/2) (n) =
sin(a/2)cos(b/2) (l) + cos(a/2)sin(b/2) (m) + sin(a/2)sin(b/2) (l x m)
Args:
rv1, rv2: Axis-angle rotation Tensors with shape [batch_size, 3]
Returns:
Axis-angle rotation in [batch_size, 3] Tensor which when applied is
equivalent to application of rv2 then rv1
@blzq
blzq / hide-netflix-synopses
Last active August 3, 2018 08:57
Hide Netflix episode synopses - filters for uBlock Origin
www.netflix.com##.episodeSynopsis
www.netflix.com##.nfa-w-60.nfa-m-0.nfa-c-gray-80.nfa-fs-1-6-em
www.netflix.com##.synopsis
www.netflix.com##.WatchNext-episode-synopsis