2

I would like to apply a radial average at the end of a keras pipeline.

At the second to last step, I have an image of size n x n. I then want to map this n x n image to a 1 x n/2 vector, where vector[x] = mean(image(radialPosition = x)). I.e. I want to average all points of distance X from the center of the image, and set this as output[x]. We can assume that n is odd, so the center point is a single point.

I have considered looping over all radii, and selecting the desired indices, as well as a dot product between the image and multiple "averaging" matrices, but neither of these seem computationally efficient.

Is there a better way of doing this?

clang
  • 23
  • 2
  • Possible duplicate https://stackoverflow.com/questions/48842320/what-is-the-best-way-to-calculate-radial-average-of-the-image-with-python ? – Anakin Apr 09 '19 at 19:54
  • That is the effect that I want to capture, but I want to encorperate this into a keras pipeline. I.e. I want to do this operation as the last step in my NN model. – clang Apr 09 '19 at 20:04
  • Are you sure you want to use this as a `Layer` in Keras? As a last layer, it sounds strange to me. I was expecting you want this as a loss function maybe. But anyway, you can write a custom Keras `Layer` for this. More info here [https://keras.io/layers/writing-your-own-keras-layers/ ]. – Anakin Apr 09 '19 at 20:12

0 Answers0