當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.magnitude方法代碼示例

本文整理匯總了Python中cv2.magnitude方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.magnitude方法的具體用法?Python cv2.magnitude怎麽用?Python cv2.magnitude使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.magnitude方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_mag_avg

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def get_mag_avg(img):

    img = np.sqrt(img)

    kernels = get_kernels()

    mag = np.zeros(img.shape, dtype='float32')

    for kernel_filter in kernels:

        gx = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[1], borderType=cv2.BORDER_REFLECT)
        gy = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[0], borderType=cv2.BORDER_REFLECT)

        mag += cv2.magnitude(gx, gy)

    mag /= len(kernels)

    return np.uint8(mag) 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:20,代碼來源:spfunctions.py

示例2: get_mag_ang

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def get_mag_ang(img):

    """
    Gets image gradient (magnitude) and orientation (angle)

    Args:
        img

    Returns:
        Gradient, orientation
    """

    img = np.sqrt(img)

    gx = cv2.Sobel(np.float32(img), cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(np.float32(img), cv2.CV_32F, 0, 1)

    mag, ang = cv2.cartToPolar(gx, gy)

    return mag, ang, gx, gy 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:22,代碼來源:spfunctions.py

示例3: grad_mag

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def grad_mag(ch_bd):

    # normalize
    mu_ = ch_bd.mean()
    std_ = ch_bd.std()
    ch_bd = np.divide(np.subtract(ch_bd, mu_), std_)

    ch_bd[np.isnan(ch_bd)] = 0
    ch_bd += abs(ch_bd.min())

    # compute gradient orientation and magnitude
    return get_mag_ang(ch_bd) 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:14,代碼來源:spfunctions.py

示例4: fourier_transform

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
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)) 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:13,代碼來源:spfunctions.py

示例5: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def main():
    # read an image 
    img = cv2.imread('../figures/flower.png')
    
    # create cropped grayscale image from the original image
    crop_gray = cv2.cvtColor(img[100:400, 100:400], cv2.COLOR_BGR2GRAY)
    
    # take discrete fourier transform 
    dft = cv2.dft(np.float32(crop_gray),flags = cv2.DFT_COMPLEX_OUTPUT)
    dft_shift = np.fft.fftshift(dft)
    magnitude_spectrum = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1]))
    
    # plot results
    plot_dft(crop_gray, magnitude_spectrum) 
開發者ID:PacktPublishing,項目名稱:Practical-Computer-Vision,代碼行數:16,代碼來源:03_fourier_transform.py

示例6: filter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def filter(self, image):
        """
        Filter the given image with the Gabor kernels in this bank.

        Parameters
        ----------
        image: numpy.array
            Image to be filtered.

        Returns
        -------
        responses: numpy.array
            List of the responses of the filtering with the Gabor kernels. The
            responses are the magnitude of both the real and imaginary parts of
            the convolution with each kernel, hence this list dimensions are the
            same of the image, plus another dimension for the 32 responses (one
            for each kernel in the bank, since there are 4 wavelengths and 8
            orientations).
        """

        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        responses = []
        for wavelength in self._wavelengths:
            for orientation in self._orientations:

                # Get the kernel
                frequency = 1 / wavelength
                par = KernelParams(wavelength, orientation)
                kernel = self._kernels[par]

                # Filter with both real and imaginary parts
                real = cv2.filter2D(image, cv2.CV_32F, kernel.real)
                imag = cv2.filter2D(image, cv2.CV_32F, kernel.imag)

                # The response is the magnitude of the real and imaginary
                # responses to the filters, normalized to [-1, 1]
                mag = cv2.magnitude(real, imag)
                cv2.normalize(mag, mag, -1, 1, cv2.NORM_MINMAX)

                responses.append(mag)

        return np.array(responses) 
開發者ID:luigivieira,項目名稱:emotions,代碼行數:45,代碼來源:gabor.py

示例7: feature_fourier

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import magnitude [as 別名]
def feature_fourier(chBd, blk, scs, end_scale):

    rows, cols = chBd.shape
    scales_half = int(end_scale / 2.0)
    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, dtype='float32')

    for i in range(0, rows-scales_blk, blk):

        for j in range(0, cols-scales_blk, blk):

            for k in scs:

                k_half = int(k / 2.0)

                ch_bd = chBd[i+scales_half-k_half:i+scales_half-k_half+k,
                             j+scales_half-k_half:j+scales_half-k_half+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.0 * 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.0
                    else:
                        out_list[pix_ctr] = st[0][0]

                    pix_ctr += 1

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

    return out_list 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:60,代碼來源:spfunctions.py


注:本文中的cv2.magnitude方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。