<jupyter_start><jupyter_text><jupyter_code>from PIL import Image
import requests
#images for testing
im1 = Image.open(requests.get("https://previews.123rf.com/images/garsya/garsya1503/garsya150300004/37818947-blank-square-cookie-on-the-white-background.jpg", stream=True).raw)
im2 = Image.open(requests.get("https://previews.123rf.com/images/reamolko/reamolko1502/reamolko150200073/36802200-crispy-cracker-isolated-crunchy-biscuit-yellow-square-cookie-.jpg", stream=True).raw)

def pad(img, h, w):
    top_pad = np.floor((h - img.shape[0]) / 2).astype(np.uint16)
    bottom_pad = np.ceil((h - img.shape[0]) / 2).astype(np.uint16)
    right_pad = np.ceil((w - img.shape[1]) / 2).astype(np.uint16)
    left_pad = np.floor((w - img.shape[1]) / 2).astype(np.uint16)
    return np.copy(np.pad(img, ((top_pad, bottom_pad), (left_pad, right_pad), (0, 0)), mode='symmetric'))
def img_mse(im1, im2):
    h = max(np.array(im1).shape[0], np.array(im2).shape[0])
    w = max(np.array(im1).shape[1], np.array(im2).shape[1])
    img1_pad = pad(np.array(im1), h,w)
    img2_pad = pad(np.array(im2), h,w)
    return np.square(np.subtract(img1_pad, img2_pad)).mean()
img_mse(im1, im2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18729372937293728, 'fraction_numerical': 0.07095709570957096, 'mean_word_length': 4.538812785388128, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '202392', 'license': 'MIT', 'n_tokens_mistral': 551, 'n_tokens_neox': 509, 'n_words': 64, 'path': 'IMG_MSE.ipynb', 'repo_name': 'mal-cul1830/Algorithmic-Toolbox-San-Diego', 'size': '1212'}