3

我有两组图像存储为 3D numpy 数组。所有图像的尺寸相同(28X28)。我想使用 compare_ssim 比较每组中的图像。我写了下面的代码非常慢。我尝试使用 numpy.apply_along_axis 进行矢量化,但这失败并出现 X.shape<>Y.shape 错误。有什么建议么?

from skimage.measure import compare_ssim as ssim

def max_ssim(image,ref_images):
    max_score = -1 #Minimum SSIM score possible is -1
    for ref_image in ref_images:
        score = ssim(image,ref_image)
        if score > max_score:
            max_score = score
    return max_score

def overlap_between_sets(test_set, ref_set):
    #return a vector for each row of the test set which 
    #contains the MAX SSIM Score found against ref_set
    # SSIM scores range between -1 and 1 where 1 is identical.

    overlap = np.ndarray(test_set.shape[0], dtype=np.float32)
    for i, obs in enumerate(test_set):
        overlap[i] = max_mse_vec(obs,ref_set)
    return overlap

test_to_train_overlap = overlap_between_sets(test_dataset,train_dataset)
4

0 回答 0