I'm currently using SSIM (code below) to compare the similarity between two black and white images of the same size (see images below). By similarity, I mean an overall similar shape of the black structure within the image + similar features (e.g. similar number, size, and relative position of the white spots in the structure- see image below for reference).
However, when I compare these two images that have the exact same structure but one of the structures is shifted slightly upwards, ssim gives a score of 0.24, which for my purpose, doesn't make sense since the two structures have the exact same shape and features.
Is there an image similarity metric better suited for this purpose? I've been looking into FSIM but haven't figured out how to implement it yet.
from skimage.metrics import structural_similarity as ssim
def ssim_calc(img_1,img_2):
img_1_ss=cv2.imread(img_1)
img_2_ss= cv2.imread(img_2)
img_1_gray = cv2.cvtColor(img_1_ss, cv2.COLOR_BGR2GRAY)
img_2_gray = cv2.cvtColor(img_2_ss, cv2.COLOR_BGR2GRAY)
dist=ssim(img_1_gray,img_2_gray,data_range=255)
return dist
ssim_calc('img_1.jpg','img_1_shifted.jpg')
output: 0.24120089058291322
here are the individual images if you'd like to right click & save them, should be 64x128