【问题标题】:Implementing high-pass filter in tensorflow在张量流中实现高通滤波器
【发布时间】:2017-09-02 22:05:55
【问题描述】:

我需要在张量流中提取高频图像。 基本上来自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)

但是我不知道如何在给定 sigma 的张量流中获取高斯权重。

【问题讨论】:

    标签: tensorflow convolution


    【解决方案1】:

    只需参考这个 tflearn 数据增强-http://tflearn.org/data_augmentation/ 在这里你可以找到 add_random_blur(sigma_max=5.0) 通过应用具有随机 sigma (0., sigma_max) 的高斯滤波器来随机模糊图像.

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 2018-04-03
      • 2019-12-08
      • 2018-01-26
      • 2021-07-20
      • 2012-12-02
      • 2017-05-09
      • 2012-07-14
      • 1970-01-01
      相关资源
      最近更新 更多