Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding local minima on a 2D map using tensorflow

I am trying to detect location and values of local minima on a 2D image map using tensorflow. Since this is not trivial I was wondering what a robust and efficient way in tf might be?

So far I thought of simple horizontal and vertical convolutions using [-1 1] kernels.

like image 457
oeb Avatar asked May 17 '26 19:05

oeb


1 Answers

You can find your local maxima with pooling like this:

import tensorflow as tf

def get_local_maxima(in_tensor):
  max_pooled_in_tensor = tf.nn.pool(in_tensor, window_shape=(3, 3), pooling_type='MAX', padding='SAME')
  maxima = tf.where(tf.equal(in_tensor, max_pooled_in_tensor), in_tensor, tf.zeros_like(in_tensor))
  return maxima

For local minima it would be easiest to negate the input and then find the maxima, since for pooling_type only AVG and MAX are supported so far.

Why does this work? The only time the value at some index of in_tensor is the same as the the value at the same index in max_pooled_in_tensor is if that value was the highest in the 3x3 neighborhood centered on that index in in_tensor.

like image 85
Hebi Avatar answered May 20 '26 16:05

Hebi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!