[英]How to get H1 and DC images from FFT of a series of images of organ moving over time
我有一系列心跳的图像,如何随着时间的推移进行傅立叶变换以从中提取 DC 和 H1 图像? 到目前为止,我尝试了以下代码,但我不知道 H1 到底是什么! 所以我无法提取该组件的图像! 这是我到目前为止尝试过的代码:
import numpy as np
import cv2 as cv
for sl in range(img.shape[2]):
for fr in range(1,img.shape[3]):
#|=======================================================|
#| xx Thresholding xx |
#|-------------------------------------------------------|
th_f = cv.adaptiveThreshold(img[:,:,sl,fr ].astype('uint8'),255,cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY,11,4)
th_f0 = cv.adaptiveThreshold(img[:,:,sl,fr-1].astype('uint8'),255,cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY,11,4)
#|=======================================================|
#| xx Fourier HPF Filter (Smoothing & Denoising) xx |
#|-------------------------------------------------------|
# Fourier 2D Transform
f = np.fft.fft2(th_f)
f0 = np.fft.fft2(th_f0)
# Move the DC component of the FFT output to the center of the spectrum
fshift = np.fft.fftshift(f)
fshift0 = np.fft.fftshift(f0)
# Save the original fshift
fshift_orig = fshift.copy()
fshift0_orig = fshift0.copy()
# Create mask
rows, cols = img.shape[0],img.shape[1]
crow, ccol = int(rows/2), int(cols/2)
# Use mask to remove low frequency components
dist1 = 30
#dist2 = 0
fshift[crow-dist1:crow+dist1, ccol-dist1:ccol+dist1] = 0
#fshift[crow-dist2:crow+dist2, ccol-dist2:ccol+dist2] = fshift_orig[crow-dist2:crow+dist2, ccol-dist2:ccol+dist2]
fshift0[crow-dist1:crow+dist1, ccol-dist1:ccol+dist1] = 0
#fshift0[crow-dist2:crow+dist2, ccol-dist2:ccol+dist2] = fshift0_orig[crow-dist2:crow+dist2, ccol-dist2:ccol+dist2]
#-----calculate the derivative of the 2D FFT with respect to time-----------
dfdt = fshift - fshift0 + result
#print(np.max(result))
# inverse Fourier transform
img_back = np.fft.ifft2(dfdt)
# get rid of imaginary part by abs
Fresult = np.abs(img_back).astype('uint8')
cv.imshow(Fresult)
cv.waitKey(0)
cv.destroyAllWindows()
for sl in range(img.shape[2]):
#-----Fourier--H1-----------------------------------------
# ff1[:, :, 1] H1 compnent 1, if 0 then DC
ff1 = FFT.fftn(img[:,:,sl,:])
fh = np.absolute(FFT.ifftn(ff1[:, :, 1]))
#-----Fourier--H1-----------------------------------------
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.