Python 不对称图像的检测

Python 不对称图像的检测,python,scikit-image,Python,Scikit Image,我需要用略读法测试图像的不对称性 到目前为止,我已经将图像分为四个象限,并考虑比较它们以测试对称性 下面是将它们转换为象限的函数 def image_into_quadrants(image): nrows, ncols = image.shape rsplit, csplit = nrows // 2, ncols //2 quadrants = [ image[:rsplit, :csplit], image[:rsplit,

我需要用略读法测试图像的不对称性

到目前为止,我已经将图像分为四个象限,并考虑比较它们以测试对称性

下面是将它们转换为象限的函数

def image_into_quadrants(image):
    nrows, ncols = image.shape
    rsplit, csplit = nrows // 2, ncols //2
    
    quadrants = [
        image[:rsplit, :csplit],
        image[:rsplit, csplit:],
        image[rsplit:, :csplit],
        image[rsplit:, csplit:],
        ]
    return quadrants

如何使用象限图像来比较和测试不对称性?

在我看来,如果你想知道左半部是右半部的镜像还是上半部是下半部的镜像,你应该比较一半而不是象限

考虑到这一点,我将图像分成左右两半,翻转右半并进行比较。然后我将图像分成上下两半,翻转底部(围绕另一个轴)并进行比较

我计算了对称性,使其在0..1范围内,如下所示:

symmetry = intersection of pixels between halves / union of pixels between halves
代码如下:

#!/usr/bin/env python3

import cv2
import numpy as np

def TestSymmetry(A, B):
    """Test the symmetry between two images by calculating the intersection/union of pixels"""
    intersection = cv2.bitwise_and(A,B)
    # DEBUG cv2.imwrite('intersection.png', intersection)
    union = cv2.bitwise_or(A,B)
    # DEBUG cv2.imwrite('union.png', union)
    res = cv2.countNonZero(intersection)/cv2.countNonZero(union)
    return res

# Read image in greyscale and get shape and centres
im = cv2.imread('image.png',0)
h, w = im.shape
ch, cw = h//2, w//2

# Test left-right symmetry
left  = im[:, :cw]
right = im[:, cw:]
LR = TestSymmetry(left, np.flip(right, axis=1))

# Test top-bottom symmetry
top = im[:ch, :]
bot = im[ch:, :]
TB = TestSymmetry(top, np.flip(bot, axis=0))
print(f'{int(LR*100)} {int(TB*100)}')
然后,我将一个正方形滑过另一个正方形,并在底部用两个不同轴的结果对其进行注释

当滑动正方形与静止的中心正方形重合时,希望您可以看到左右对称性增加到100%。而且,上下对称始终是100%,因为图像的上半部分和下半部分始终是对称的


我刚意识到你想使用撇渣而不是OpenCV。我相信你可以非常简单地翻译它,或者使用下面的3Numpy等价物:

intersection = np.bitwise_and(A,B)

union = np.bitwise_or(A,B)

res = np.count_nonzero(intersection)/np.count_nonzero(union)


关键词:图像处理、Python、skimage、scikit Image、OpenCV、对称、对称、不对称、非对称、交集、并集。

如何:当你有一个图像(W、H)的像素(x、y)时,你可以计算对称点并逐一比较?你如何计算对称点?