tensorflow和cv2在形态学操作上的区别
tf.nn.erosion2d、tf.nn.dilation2d和cv2.erode,cv2.dilate的区别:
1.结果的区别:
实验:
原图片:(来自西工大NWPU-RESISC45数据集)
用tf.nn.erosion2d的代码
import tensorflow as tf
import skimage.io as io
import keras.backend as K
import numpy as np
from matplotlib import pyplot as plt
kernel = K.random_normal(shape = (3, 3, 1))
img = io.imread('./airplane.png')
img = tf.convert_to_tensor(img ,tf.float32) #将array转化为tensor
img = tf.expand_dims(img, 0) #升维度
img = tf.expand_dims(img, 3)
img1 = tf.nn.erosion2d(img, kernel, strides = [1,1,1,1], rates = [1,1,1,1], padding = "SAME")#图像腐蚀
with tf.Session() as sess:
imgout