Loss function based on similarity of a patterns

Given two patterns/images A and B, is there any loss function that would compute how these patterns are similar?

There are lots of different loss functions you could use, depending on how simple you want to make things, and what aspect of image similarity you care about. It’s a huge field with lots of ongoing active research. Some keywords to search are “perceptual similarity” “image similarity metric” “structural similarity”.

The simplest thing you could do is use MSE (Mean Squared Error).