用于Scipy中RGB图像分析的多元正态pdf

时间:2018-12-19 14:43:44

标签: python scipy normal-distribution

我想通过使用3D多元正态分布的概率密度函数来检测RGB图像中的“天空”像素。我正在使用包含天空中某些像素的图像补丁来计算RGB通道的均值和方差,然后调用multivariate_normal.pdf函数来计算图像中每个像素属于多元变量的概率天空补丁的分布。我假设协方差矩阵是对角线的,这意味着RGB通道是独立的。

import numpy as np
import cv2
import matplotlib.pyplot as plt
from scipy.stats import multivariate_normal
from scipy.stats import norm

imBGR = cv2.imread("../ressources/house.jpg")
patch_sky = cv2.imread("../ressources/sky_patch.png")

# Gaussian model for sky

means = np.array([np.mean(patch_sky[:, :, 0]), np.mean(patch_sky[:, :, 1]), np.mean(patch_sky[:, :, 2])])

var = np.array([np.var(patch_sky[:, :, 0]), np.var(patch_sky[:, :, 1]), np.var(patch_sky[:, :, 2])])

proba = multivariate_normal.pdf(imBGR, mean=means, cov=var)

print("proba shape:", np.shape(proba))
print("maximum probability:", np.max(proba))

问题在于所计算出的最大概率非常低:

proba shape: (960, 1280)
maximum probability: 0.00010730705050040148

我在做什么错了?

0 个答案:

没有答案