Tensorflow生成高斯模糊並進行卷積操作

2021-10-02 00:19:05 字數 638 閱讀 6969

在卷積神經網路中用到了高斯模糊核對影象進行預處理。

首先根據方差生成模糊核:

def gauss_kernel1d(sigma):#sigma表示方差

if sigma == 0:

return 0

else:

tail = int(sigma*3)

k = tf.exp([-0.5*x**2/sigma**2 for x in range(-tail, tail+1)])

return k / tf.reduce_sum(k)

利用生成的模糊核分別對影象進行卷積

def separable_filter3d(vol, kernel):

if kernel == 0:

return vol

else:

strides = [1, 1, 1, 1]

return tf.nn.conv2d(tf.nn.conv2d(

vol,

tf.reshape(kernel, [-1, 1, 1, 1]), strides, "same"),

tf.reshape(kernel, [1, -1, 1, 1]), strides, "same")#先對x方向進行卷積,在對y方向進行卷積

Python opencv學習記錄7 高斯模糊

高斯模糊 英語 gaussian blur 通常用它來減少影象雜訊以及降低細節層次。這種模糊技術生成的影象,其視覺效果就像是經過乙個半透明的螢幕觀察影象。在計算機視覺演算法中,高斯模糊通常用於預處理階段,降低高斯雜訊,以增強影象在不同比例大小下的影象效果。若想更加細緻地了解高斯模糊原理,可以參考高斯...

tensorflow 張量生成

coding utf 8 import tensorflow as tf import numpy as np 建立張量 a tf.constant 1 5 dtype tf.int64 print a a print a.dtype a.dtype print a.shape a.shape a ...

tensorflow生成多個tfrecord檔案

import tensorflow as tf from pil import image import matplotlib.pyplot as plt import numpy as np import os i 0 j 0 num shards 100 總共寫入的檔案個數 instances ...