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
评论列表
文章目录