2017-04-07 112 views
2

我需要從張量流中提取圖像的高頻。 基本上從ndimage.gaussian_filter(img, sigma) 功能下面的代碼按預期工作:在張量流中實現高通濾波器

import tensorflow as 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') 

# as tensorflow constants with 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)) 


with tf.Session() as sess: 
    # get low/high pass ops 
    lowpass = tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME') 
    highpass = x-lowpass 

    # get high pass image 
    l = sess.run(highpass) 
    l = l.reshape(img.shape[0],img.shape[1]) 

    imshow(l) 

不過我不知道得高斯權重與給定的Σtensorflow內是如何形成的。

回答

0

只是指該tflearn數據augmentation- http://tflearn.org/data_augmentation/這裏u能找到add_random_blur(sigma_max = 5.0)隨機地通過應用高斯濾波器與隨機西格馬(0,sigma_max)模糊的圖像。