Python cv2 模块,meanStdDev() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用cv2.meanStdDev()

项目:pytorch-planet-amazon    作者:rwightman    | 项目源码 | 文件源码
def main():

    jpg_inputs = find_inputs(JPGPATH, types=('.jpg',), prefix=PREFIX)
    tif_inputs = find_inputs(TIFPATH, types=('.tif',), prefix=PREFIX)

    jpg_stats = []
    for f in jpg_inputs:
        img = cv2.imread(f[1])
        mean, std = cv2.meanStdDev(img)
        jpg_stats.append(np.array([mean[::-1] / 255, std[::-1] / 255]))
    jpg_vals = np.mean(jpg_stats, axis=0)
    print(jpg_vals)

    tif_stats = []
    for f in tif_inputs:
        img = cv2.imread(f[1], -1)
        img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)
        mean, std = cv2.meanStdDev(img)
        tif_stats.append(np.array([mean, std]))
    tif_vals = np.mean(tif_stats, axis=0)
    print(tif_vals)
项目:Yugioh-bot    作者:will7200    | 项目源码 | 文件源码
def get_image_stats(img, left=0, top=0, width=0, height=0):
        crop_img = img[top:(top + height), left:(left + width)]
        (means, stds) = cv2.meanStdDev(crop_img)
        stats = np.concatenate([means, stds]).flatten()
        return stats
项目:face-landmark    作者:lsy17096535    | 项目源码 | 文件源码
def preprocess(self, resized, landmarks):
        #ret = resized.astype('f4')
        #ret -= self.mean
        #ret /= (1.e-6+ self.std)
        #return  ret, (landmarks/40.)-0.5
        grayImg = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY).astype('f4')
        m, s = cv2.meanStdDev(grayImg)
        grayImg = (grayImg-m)/(1.e-6 + s)
        return  grayImg, landmarks/60.
项目:imgProcessor    作者:radjkarl    | 项目源码 | 文件源码
def varianceOfLaplacian(img):
    ''''LAPV' algorithm (Pech2000)'''
    lap = cv2.Laplacian(img, ddepth=-1)#cv2.cv.CV_64F)
    stdev = cv2.meanStdDev(lap)[1]
    s = stdev[0]**2
    return s[0]
项目:imgProcessor    作者:radjkarl    | 项目源码 | 文件源码
def normalizedGraylevelVariance(img):
    ''''GLVN' algorithm (Santos97)'''
    mean, stdev = cv2.meanStdDev(img)
    s = stdev[0]**2 / mean[0]
    return s[0]
项目:pytorch-planet-amazon    作者:rwightman    | 项目源码 | 文件源码
def __call__(self, img):
        # This should still be a H x W x C Numpy/OpenCv compat image, not a Torch Tensor
        assert isinstance(img, np.ndarray)
        mean, std = cv2.meanStdDev(img)
        mean, std = mean.astype(np.float32), std.astype(np.float32)
        img = img.astype(np.float32)
        img = (img - np.squeeze(mean)) / (np.squeeze(std) + self.std_epsilon)
        return img
项目:spfeas    作者:jgrss    | 项目源码 | 文件源码
def fourier_transform(ch_bd):

    dft = cv2.dft(np.float32(ch_bd), flags=cv2.DFT_COMPLEX_OUTPUT)
    dft_shift = np.fft.fftshift(dft)

    # get the Power Spectrum
    magnitude_spectrum = 20. * np.log(cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1]))

    psd1D = azimuthal_avg(magnitude_spectrum)

    return list(cv2.meanStdDev(psd1D))
项目:spfeas    作者:jgrss    | 项目源码 | 文件源码
def feature_fourier(chBd, blk, scs, end_scale):

    rows, cols = chBd.shape
    scales_half = int(end_scale / 2)
    scales_blk = end_scale - blk
    out_len = 0
    pix_ctr = 0

    for i in range(0, rows-scales_blk, blk):
        for j in range(0, cols-scales_blk, blk):
            for k in scs:
                out_len += 2

    # set the output list
    out_list = np.zeros(out_len).astype(np.float32)

    for i in range(0, rows-scales_blk, blk):
        for j in range(0, cols-scales_blk, blk):
            for k in scs:

                ch_bd = chBd[i+scales_half-(k/2):i+scales_half-(k/2)+k, j+scales_half-(k/2):j+scales_half-(k/2)+k]

                # get the Fourier Transform
                dft = cv2.dft(np.float32(ch_bd), flags=cv2.DFT_COMPLEX_OUTPUT)
                dft_shift = np.fft.fftshift(dft)

                # get the Power Spectrum
                magnitude_spectrum = 20. * np.log(cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1]))

                psd1D = azimuthal_avg(magnitude_spectrum)

                sts = list(cv2.meanStdDev(psd1D))

                # plt.subplot(121)
                # plt.imshow(ch_bd, cmap='gray')
                # plt.subplot(122)
                # plt.imshow(magnitude_spectrum, interpolation='nearest')
                # plt.show()
                # print psd1D
                # sys.exit()

                for st in sts:

                    if np.isnan(st[0][0]):
                        out_list[pix_ctr] = 0.
                    else:
                        out_list[pix_ctr] = st[0][0]

                    pix_ctr += 1

    out_list[np.isnan(out_list) | np.isinf(out_list)] = 0.

    return out_list