【问题标题】:Compute variance of image计算图像的方差
【发布时间】:2020-06-30 07:21:36
【问题描述】:

我想在不使用 opencv 的情况下计算图像的拉普拉斯方差,因为 opencv 非常庞大。所以,我想使用任何其他尺寸更小的库。

这是我当前的代码。它工作完美,但使用 opencv-python-headless:

import cv2

image = cv2.imread("images/test.png")
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

laplacian = cv2.Laplacian(image_gray, cv2.CV_64F).var()
print(laplacian)

如何使用任何其他尺寸较小的库获得相同的结果(相同的拉普拉斯值)?

【问题讨论】:

    标签: python image-processing scikit-image


    【解决方案1】:

    您可以考虑使用scipy 代替其laplacian function

    from scipy import ndimage #To compute the laplacian
    import imageio #To load the image as a numpy array
    import numpy as np #To convert it to gray
    
    #A function to convert your rgb image to gray
    convert_to_gray = lambda rgb : np.dot(rgb[... , :3] , [0.299 , 0.587, 0.114]) 
    
    image = imageio.imread("images/test.png")
    image_gray = convert_to_gray(image)
    
    laplacian = ndimage.laplace(image_gray).var()
    print(laplacian)
    

    【讨论】:

      【解决方案2】:

      您首先需要将图像与拉普拉斯核进行卷积:

      为此,您可以使用任何可以将图像加载到二维数组中的库。 Python“枕头”库可能很有用。 然后你只需要计算图像的方差。 这里已经回答了: https://stackoverflow.com/questions/9938008/variance-and-mean-of-image#:~:text=2%20Answers&text=These%20are%20indeed%20the%20correct,x%20%2D%20mean(x))。

      【讨论】:

        猜你喜欢
        • 2013-02-27
        • 2015-05-09
        • 1970-01-01
        • 2017-05-10
        • 2018-06-27
        • 2020-03-31
        • 2021-07-16
        • 1970-01-01
        • 2020-07-25
        相关资源
        最近更新 更多