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. html中的form不提交(排除)某些input 原創(chuàng)2. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享3. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式4. jsp文件下載功能實(shí)現(xiàn)代碼5. 開(kāi)發(fā)效率翻倍的Web API使用技巧6. ASP常用日期格式化函數(shù) FormatDate()7. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼8. CSS3中Transition屬性詳解以及示例分享9. asp.net core項(xiàng)目授權(quán)流程詳解10. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫(huà)特效
