convolution - Implementing high-pass filter in tensorflow -
i need extract high frequencies form image in tensorflow. functionality ndimage.gaussian_filter(img, sigma)
following code works expected:
import tensorflow tf import cv2 img = cv2.imread(imgpath, cv2.imread_grayscale) img = cv2.normalize(img.astype('float32'), none, 0.0, 1.0, cv2.norm_minmax) # gaussian filter k = np.array([[0.003765,0.015019,0.023792,0.015019,0.003765], [0.015019,0.059912,0.094907,0.059912,0.015019], [0.023792,0.094907,0.150342,0.094907,0.023792], [0.015019,0.059912,0.094907,0.059912,0.015019], [0.003765,0.015019,0.023792,0.015019,0.003765]], dtype='float32') # tensorflow constants correct shapes x = tf.constant(img.reshape(1,img.shape[0],img.shape[1], 1)) w = tf.constant(k.reshape(k.shape[0],k.shape[1], 1, 1)) tf.session() sess: # low/high pass ops lowpass = tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='same') highpass = x-lowpass # high pass image l = sess.run(highpass) l = l.reshape(img.shape[0],img.shape[1]) imshow(l)
however don't know how gaussian weights form within tensorflow given sigma.
just refer tflearn data augmentation-http://tflearn.org/data_augmentation/ here u can find add_random_blur(sigma_max=5.0) randomly blur image applying gaussian filter random sigma (0., sigma_max).
Comments
Post a Comment