utils.py
def color_hist_diff(image1, image2, patch_size=16):
    """
    calculate the color histogram difference of two images
    """
    # get dimesion and patch
    vertical, horizontal, Z = image1.shape
    v_patch = vertical // 16
    h_patch = horizontal // 16
    # calculate difference
    diff = 0
    for z in range(Z):
        img1, img2 = image1[:, :, z], image2[:, :, z]
        for i in range(0, img1.shape[0] - v_patch + 1, patch_size):
            for j in range(0, img1.shape[1] - h_patch + 1, patch_size):
                patch1 = img1[i:i + v_patch, j:j + h_patch].flatten()
                patch2 = img2[i:i + v_patch, j:j + h_patch].flatten()
                hist1 = np.histogram(patch1, bins=np.arange(257), density=True)
                hist2 = np.histogram(patch2, bins=np.arange(257), density=True)
                diff += np.linalg.norm(hist1[0] - hist2[0])
    return diff

    calculate the color histogram difference of two images
    
calculate the color histogram difference of two images
calculate the color histogram difference of two images
def color_hist_diff(image1, image2, patch_size=16):
    vertical, horizontal, Z = image1.shape
    v_patch = vertical // 16
    h_patch = horizontal // 16
    diff = 0
    for z in range(Z):
        img1, img2 = image1[:, :, z], image2[:, :, z]
        for i in range(0, img1.shape[0] - v_patch + 1, patch_size):
            for j in range(0, img1.shape[1] - h_patch + 1, patch_size):
                patch1 = img1[i:i + v_patch, j:j + h_patch].flatten()
                patch2 = img2[i:i + v_patch, j:j + h_patch].flatten()
                hist1 = np.histogram(patch1, bins=np.arange(257), density=True)
                hist2 = np.histogram(patch2, bins=np.arange(257), density=True)
                diff += np.linalg.norm(hist1[0] - hist2[0])
    return diff
def color_hist_diff ( image1 , image2 , patch_size = 16 ) : vertical , horizontal , Z = image1 . shape v_patch = vertical // 16 h_patch = horizontal // 16 diff = 0 for z in range ( Z ) : img1 , img2 = image1 [ : , : , z ] , image2 [ : , : , z ] for i in range ( 0 , img1 . shape [ 0 ] - v_patch + 1 , patch_size ) : for j in range ( 0 , img1 . shape [ 1 ] - h_patch + 1 , patch_size ) : patch1 = img1 [ i : i + v_patch , j : j + h_patch ] . flatten ( ) patch2 = img2 [ i : i + v_patch , j : j + h_patch ] . flatten ( ) hist1 = np . histogram ( patch1 , bins = np . arange ( 257 ) , density = True ) hist2 = np . histogram ( patch2 , bins = np . arange ( 257 ) , density = True ) diff += np . linalg . norm ( hist1 [ 0 ] - hist2 [ 0 ] ) return diff
calculate the color histogram difference of two images
calculate the color histogram difference of two images
"""
    calculate the color histogram difference of two images
    """ # get dimesion and patch # calculate difference
image1
image2
patch_size