A Domain-specific Perceptual Metric via Contrastive Self-supervised Representation: Applications on Natural and Medical Images