numpy-->フーリエ変換

672 ワード

import numpy as np
from PIL import Image
from numpy.fft import fft, ifft
def filter_img(src_img):
    #           
    img = Image.open(src_img)
    #         
    src_array = np.frombuffer(img.tobytes(), dtype=np.uint8)
    
    #            
    #   -->   
    result = fft(src_array)
    #  
    result = np.where(np.absolute(result)<9e4,0,result)
    
    #      ,    
    #   -->   
    result = ifft(result)
    
    #    
    result = np.uint8(np.real(result))
    
    #     
    im = Image.frombytes(img.mode,img.size,result)
    
    #    
    im.show()
    
filter_img('TIM  20180613143307.jpg')