Erosion and Dilation in Tensorflow
Guys, I'm looking for a way to implement or run erosion and dilation on my image mask in TensorFlow 1.15. I've got a simple binary mask and want something like this.
How to do it with TensorFlow 1.*?
Guys, I'm looking for a way to implement or run erosion and dilation on my image mask in TensorFlow 1.15. I've got a simple binary mask and want something like this.
How to do it with TensorFlow 1.*?
There is another option for it. You can do it by using the max-pooling operation of Tensorflow and it does not have to be of version 2. Here is how you can do it.
erosion = -tf.nn.max_pool2d(-x, ksize=(k, k), stride=1, name='erosion2D')
dilation = tf.nn.max_pool2d(x, ksize=(k, k), stride=1, name='dilation2D')
It is a short way to have dilation and erosion in Tensorflow overall.
There are 2 implementations in Tensorflow for erosion and dilation in 2D.
tf.nn.erosion2d(
value,
filters,
strides,
padding,
data_format,
dilations,
name=None
)
tf.nn.dilation2d(
input,
filters,
strides,
padding,
data_format,
dilations,
name=None
)
The official doc of this implementation is written in Tensorflow 2.*, but I believe it will work in Tensorflow 1.* as well. Here are the links of tf.nn.erosion2d and tf.nn.dilation2d.