本文整理汇总了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)
示例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
示例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)
示例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))
示例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)
示例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)
示例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