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. Python文本文件的合并操作方法代碼實(shí)例2. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題3. asp讀取xml文件和記數(shù)4. Python sorted排序方法如何實(shí)現(xiàn)5. ASP.NET MVC實(shí)現(xiàn)橫向展示購物車6. 每日六道java新手入門面試題,通往自由的道路第二天7. Python 中如何使用 virtualenv 管理虛擬環(huán)境8. python利用opencv實(shí)現(xiàn)顏色檢測(cè)9. CSS自定義滾動(dòng)條樣式案例詳解10. PHP實(shí)現(xiàn)基本留言板功能原理與步驟詳解
