python用opencv 圖像傅里葉變換
傅里葉變換dft = cv.dft(np.float32(img),flags = cv.DFT_COMPLEX_OUTPUT)傅里葉逆變換img_back = cv.idft(f_ishift)
實(shí)驗(yàn):將圖像轉(zhuǎn)換到頻率域,低通濾波,將頻率域轉(zhuǎn)回到時(shí)域,顯示圖像
import numpy as npimport cv2 as cvfrom matplotlib import pyplot as pltimg = cv.imread(’d:/paojie_g.jpg’,0)rows, cols = img.shapecrow, ccol = rows//2 , cols//2dft = cv.dft(np.float32(img),flags = cv.DFT_COMPLEX_OUTPUT)dft_shift = np.fft.fftshift(dft)# create a mask first, center square is 1, remaining all zerosmask = np.zeros((rows,cols,2),np.uint8)mask[crow-30:crow+31, ccol-30:ccol+31, :] = 1# apply mask and inverse DFTfshift = dft_shift*maskf_ishift = np.fft.ifftshift(fshift)img_back = cv.idft(f_ishift)img_back = cv.magnitude(img_back[:,:,0],img_back[:,:,1])plt.subplot(121),plt.imshow(img, cmap = ’gray’)plt.title(’Input Image’), plt.xticks([]), plt.yticks([])plt.subplot(122),plt.imshow(img_back, cmap = ’gray’)plt.title(’Low Pass Filter’), plt.xticks([]), plt.yticks([])plt.show()
相關(guān)文章:
1. Idea如何去除Mapper警告方法解析2. IntelliJ IDEA設(shè)置編碼格式的方法3. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟4. ASP基礎(chǔ)入門第八篇(ASP內(nèi)建對象Application和Session)5. 使用 kind 和 Docker 啟動(dòng)本地的 Kubernetes環(huán)境6. XML入門精解之結(jié)構(gòu)與語法7. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法8. idea重置默認(rèn)配置的方法步驟9. idea自定義快捷鍵的方法步驟10. idea設(shè)置代碼格式化的方法步驟
