简体   繁体   中英

How to get H1 and DC images from FFT of a series of images of organ moving over time

I have series of images to the heart beating, how can I take Fourier Transform over time to extract from it DC and H1 images ? I tried the following code so far, but I don't know what is H1 exactly ! so I can't extract the images of that component ! here is the code I have tried so far:

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()
  • The solution was to take Fourier transform 3D for each slice, then to chose only the 2nd component of the Transform to transform it back to the spatial space, and that's it.
  • The benefit of this is to detect if something is moving along the third axis(time in my case).
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-----------------------------------------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM