How to compute l2 norm between every pixel and its 8-pixel neighborhood?

You could probably use unfold to get the image patches and calculate the loss on these.
Have a look at this post for an example.

1 Like