第3章 Python 數字圖像處理(DIP) - 灰度變換與空間濾波18 - 低通、高通、帶阻和帶通濾波器、組合使用空間增強方法

低通、高通、帶阻和帶通濾波器

得到空間濾波器的第三種方法,生成一維濾波器函數,然后要么使用式(3.42)w=vvTw = vv^Tw=vvT生成二維可分離的濾波器函數,要么旋轉這些一維函數來生成二維核。旋轉后的一維函數是圓對稱(各向同性)函數的近似。

# 低通、高通、帶阻和帶通濾波器
x = np.arange(100)
y = np.where(x > 50, x, 1)
lp = np.where(x < 50, y, 0)hp = 1 - lpplt.figure(figsize=(16, 8))
plt.subplot(2, 2, 1), plt.plot(lp), plt.title('Low Pass'), plt.xticks([]), plt.yticks([0, 1]), plt.ylim([0, 2])
plt.subplot(2, 2, 2), plt.plot(hp), plt.title('High Pass'), plt.xticks([]), plt.yticks([0, 1]), plt.ylim([0, 2])y = np.where(x > 30, x, 1)
l_1 = np.where(x < 30, y, 0)y = np.where(x > 70, x, 1)
l_2 = np.where(x < 70, y, 0)
h_1 = 1 - l_2br = h_1 + l_1
plt.subplot(2, 2, 3), plt.plot(br), plt.title('Band Resitant'), plt.xticks([]), plt.yticks([0, 1]), plt.ylim([0, 2])
bp = 1 - br
plt.subplot(2, 2, 4), plt.plot(bp), plt.title('Band Pass'), plt.xticks([]), plt.yticks([0, 1]), plt.ylim([0, 2])plt.show()

在這里插入圖片描述

同心反射板
z(x,y)=12[1+cos(x2+y2)](3.66)z(x, y) = \frac{1}{2}[1 + cos(x^2 + y^2)] \tag{3.66}z(x,y)=21?[1+cos(x2+y2)](3.66)
xxxyyy在區間[-8.2, 8.2],變化量為0.0275,所以會得到一幅597×597597\times597597×597的圖像。邊緣的黑色區域是通過將中心距離大于8.2的所有像素設置為0得到的。

597的中心是(298, 298),像素的距離應該是298

# 同心反射板
height, width = 597, 597
m = int((height - 1) / 2)
n = int((width - 1) / 2)
X = np.linspace(-8.2, 8.2, height)
Y = np.linspace(-8.2, 8.2, width)
x, y = np.meshgrid(X, Y)
circle = 0.5 * (1 + np.cos(x**2 + y**2))
for i in range(circle.shape[0]):for j in range(circle.shape[1]):if np.sqrt((i - m)**2 + (j - n)**2 ) > m:circle[i, j] = 0else:continueplt.figure(figsize=(16, 8))
plt.subplot(1, 2, 1), plt.imshow(circle, 'gray'), plt.title('Concentric circles'), plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2), plt.plot(circle[298, :]), plt.title('Frequency'), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()

在這里插入圖片描述

這是之前寫的,感覺有點不對

# 一維空間低通濾波器函數通過式(3.42)構造的二維低通濾波器
height, width = 128, 128
m = int((height - 1) / 2)
n = int((width - 1) / 2)
x = np.linspace(-6*np.pi, 6* np.pi, height)
y = np.linspace(-6*np.pi, 6* np.pi, width)
scale = 1                  # scale可以縮放濾波器的尺寸
x = np.sin(x * scale) / x
y = np.sin(y * scale) / y
x = np.array([x])
y = np.array([y])w = x * y.T# for i in range(w.shape[0]):
#     for j in range(w.shape[1]):
#         if np.sqrt((i - m)**2 + (j - n)**2 ) > m:
#             w[i, j] = 0
#         else:
#             continue
plt.figure(figsize=(16, 8))
plt.subplot(1, 2, 1), plt.imshow(w, 'gray'), plt.title('Concentric circles'), plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2), plt.plot(w[64, :]), plt.title('Frequency'), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()

在這里插入圖片描述

新增: 這個才像函數旋轉得到的
圖像看起來有點粗糙,是采樣少了,只有128,如果增加到512,會得到很好的效果。

# 一維空間低通濾波器函數通過式(3.42)構造的二維低通濾波器
height, width = 128, 128
m = int((height - 1) / 2)
n = int((width - 1) / 2)
x = np.linspace(-1*np.pi, 1* np.pi, height)
y = np.linspace(-1*np.pi, 1* np.pi, width)
x, y = np.meshgrid(x, y)
scale = 1                  # scale可以縮放濾波器的尺寸
w = np.sinc((x**2 + y**2) * scale)for i in range(w.shape[0]):for j in range(w.shape[1]):if np.sqrt((i - m)**2 + (j - n)**2 ) > m:w[i, j] = 0else:continue
plt.figure(figsize=(16, 8))
plt.subplot(1, 2, 1), plt.imshow(w, 'gray'), plt.title('Concentric circles'), plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2), plt.plot(w[64, :]), plt.title('Frequency'), #plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()

在這里插入圖片描述

# 不同的濾波器對同心圓反射板的效果,圖1效果不是很好
img_ori = circle.copy()kernel_size = 19
x = np.ones([kernel_size])
x[kernel_size//3:] = 0.1
y = np.ones_like(x)
x = np.array([x])
y = np.array([y])
w = x * y.T
img_sep = separate_kernel_conv2D(img_ori, w)
img_sep = np.uint8(normalize(img_sep) * 255)# 各向同性
height, width = img_ori.shape[:2]
m = int((height - 1) / 2)
n = int((width - 1) / 2)
x = np.linspace(-6*np.pi, 6* np.pi, 21)
y = np.linspace(-6*np.pi, 6* np.pi, 21)
scale = 0.5                  # scale可以縮放濾波器的尺寸
x = np.sin(x * scale) / (x + 1e-8)
y = np.sin(y * scale) / (y + 1e-8)
x = np.array([x])
y = np.array([y])w = x * y.Timg_sep_1 = separate_kernel_conv2D(img_ori, w)
img_sep_1 = np.uint8(normalize(img_sep_1) * 255)plt.figure(figsize=(15, 12))
plt.subplot(1, 2, 1), plt.imshow(img_sep,   'gray', vmax=255), plt.title("Original"), plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2), plt.imshow(img_sep_1, 'gray', vmax=255), plt.title("Sobel"), plt.xticks([]), plt.yticks([])plt.tight_layout()
plt.show()

在這里插入圖片描述

組合使用空間增強方法

# 1 拉普拉斯突出細節
# 2 平滑后的梯度圖像來掩蔽拉普拉斯圖像
# 3 灰度變換增大灰度級的動態范圍
# 圖1
img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH03/Fig0343(a)(skeleton_orig).tif", 0)# 圖2,拉普拉斯變換
# kernel_laplacian = np.array((
#                     [0,1,0],
#                     [1,-4,1],
#                     [0,1,0]), np.int8)
kernel_laplacian_d = np.array([[-1, -1, -1],[-1, 8, -1],[-1, -1, -1]],)
img_laplacian = cv2.filter2D(img_ori, ddepth=-1, kernel=kernel_laplacian_d)
img_laplacian = np.uint8(normalize(img_laplacian) * 255)# 圖3,原圖+拉普拉斯
img_ori_laplacian = img_ori + img_laplacian
img_ori_laplacian = normalize(img_ori_laplacian) * 255# 圖4,原圖Sobel變換
sobel_x = np.zeros([3, 3], np.int)
sobel_x[0, :] = np.array([-1, -2, -1])
sobel_x[2, :] = np.array([1, 2, 1])
sobel_y = np.zeros([3, 3], np.int)
sobel_y[:, 0] = np.array([-1, -2, -1])
sobel_y[:, 2] = np.array([1, 2, 1])
# gx = separate_kernel_conv2D(img_ori, kernel=sobel_x)
# gy = separate_kernel_conv2D(img_ori, kernel=sobel_y)
gx = cv2.filter2D(img_ori, ddepth=-1, kernel=sobel_x)
gy = cv2.filter2D(img_ori, ddepth=-1, kernel=sobel_y)
# thred = 120
# gx = np.where(gx >= thred, gx, 0)
# gx = np.where(gx < thred, gx, 1)
# gy = np.where(gy >= thred, gy, 0)
# gy = np.where(gy < thred, gy, 1)
# 先對gx gy做二值化處理再應用下面的公式
# img_sobel = np.sqrt(gx**2 + gy**2)   
img_sobel = abs(gx) + abs(gy)
img_sobel = np.uint8(normalize(img_sobel) * 255)#  圖5, 使用5x5的盒式濾波器平滑Sobel
kernel_box = np.ones([5, 5])
kernel_box = kernel_box / kernel_box.sum()
sobel_box = separate_kernel_conv2D(img_sobel, kernel=kernel_box)
sobel_box = normalize(sobel_box)
# sobel_box = np.uint8(normalize(sobel_box) * 255)# 圖6,圖2與圖5相乘的模板圖像
mask = img_laplacian * sobel_box
img_mask = np.uint8(normalize(mask) * 255)# 圖7,原圖與圖6相加
img_passi = img_ori + img_mask * 0.3
img_passi = np.uint(normalize(img_passi) * 255)# 圖8 對圖7做冪律變換
img_gamma = gamma_transform(img_passi, 1, gamma=0.5)plt.figure(figsize=(13, 40))
plt.subplot(4, 2, 1), plt.imshow(img_ori,   'gray', vmax=255), plt.title("OriginalA"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 2), plt.imshow(img_laplacian, 'gray', vmax=255), plt.title("LaplacianB"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 3), plt.imshow(img_ori_laplacian, 'gray', vmax=255), plt.title("Original + LaplacianC"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 4), plt.imshow(img_sobel, 'gray', vmax=255), plt.title("SobelD"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 5), plt.imshow(sobel_box, 'gray', vmax=1), plt.title("Sobel Box filterE"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 6), plt.imshow(img_mask, 'gray', vmax=255), plt.title("Sobel mask F"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 7), plt.imshow(img_passi, 'gray', vmax=255), plt.title("Passivation G"), plt.xticks([]), plt.yticks([])
plt.subplot(4, 2, 8), plt.imshow(img_gamma, 'gray', vmax=255), plt.title("Gamma Transform H"), plt.xticks([]), plt.yticks([])
plt.tight_layout()
plt.show()

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/260751.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/260751.shtml
英文地址,請注明出處:http://en.pswp.cn/news/260751.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MySQL兩千萬數據優化遷移

最近有一張2000W條記錄的數據表需要優化和遷移。2000W數據對于MySQL來說很尷尬&#xff0c;因為合理的創建索引速度還是挺快的&#xff0c;再怎么優化速度也得不到多大提升。不過這些數據有大量的冗余字段和錯誤信息&#xff0c;極不方便做統計和分析。所以我需要創建一張新表&…

Linux Tomcat 6.0安裝配置實踐總結

系統環境&#xff1a; Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64位 Tomcat下載 從官方網站 http://tomcat.apache.org/下載你需要的Tomcat版本&#xff0c;目前Tomcat主要版本有Tomcat 6.0、Tomcat 7.0、Tomcat 8.0三個版本&#xff0c;下面我們以6.0(6.0.39…

如何給FormPanel表單中的元素賦值以及獲取表單元素值

1.定義表單元素的name屬性如下 var HLV new Ext.form.TextField({fieldLabel: 匯率,name:EXCHANGERATE,anchor: 30%}); 2.定義數據源 var ExchangeRatestore new Ext.data.Store({proxy: new Ext.data.HttpProxy({ url: WsECOTAX01.asmx/SelectExchangeRate, method: "po…

第4章 Python 數字圖像處理(DIP) - 頻率域濾波1 - 傅里葉級數和變換簡史

本章主要講解頻域域濾波的技術&#xff0c;主要技術用到是大家熟悉的傅里葉變換與傅里葉反變換。這里有比較多的篇幅講解的傅里葉的推導進程&#xff0c;用到Numpy傅里葉變換。本章理論基礎比較多&#xff0c;需要更多的耐心來閱讀&#xff0c;有發現有錯誤&#xff0c;可以與我…

python中str是什么函數_python str函數怎么用

展開全部 是將一個2113對象轉成字符串顯示5261&#xff0c;注意只是顯示用&#xff0c;有些對象4102轉成字符串沒有直1653接的意思。 str():將變量轉化為字符串類型 a 1 b [1, 2, 3] str_a str(a) print(a) print(type(a)) str_b str(b) print(b) print(type(b)) The str()…

[ofbiz]less-than (lt;) and greater-than (gt;) symbols

問題描述&#xff1a; In field [updateItemStr] less-than (<) and greater-than (>) symbols are not allowed 此處的field [updateItemStr]是services的一個IN參數&#xff0c;錯誤描述的意思是"<,>"不能出現在這個域內。 解決辦法&#xff1a; 在ser…

分頁探究--Filter+JSTL

最近卡了一個功能就是分頁&#xff0c;查了很多資料&#xff0c;分頁大概是兩種類型&#xff1a;一種是把數據庫的東西全部查出來然后放在session里&#xff0c;用list一頁一頁傳到頁面&#xff0c;這樣的消耗比較大;另一種就是使用sql語句的limit來進行數據庫分頁查詢。我使用…

iPhone開發資料之內存管理 ,循環引用導致的內存問題

iPhone開發資料之內存管理 ,循環引用導致的內存問題 https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447 http://en.wikipedia.org/wiki/Reference_counting 【IT168 技術文檔】開…

python能做大型游戲嗎_python有做大型游戲的潛力嗎?

著作權歸作者所有。商業轉載請聯系作者獲得授權&#xff0c;非商業轉載請注明出處。 豈止是有潛力&#xff0c;簡直是很合適&#xff01; 豬廠兩大游戲客戶端引擎&#xff0c;NeoX 和 Messiah&#xff0c;都使用 Python 作為腳本語言。 你最近所了解的比較火的掛著豬廠旗號的&a…

第4章 Python 數字圖像處理(DIP) - 頻率域濾波2 - 復數、傅里葉級數、連續單變量函數的傅里葉變換、卷積

目錄基本概念復數傅里葉級數沖激函數及其取樣&#xff08;篩選&#xff09;性質連續單變量函數的傅里葉變換卷積基本概念 復數 復數CCC的定義為 CRjI(4.3)C R jI \tag{4.3}CRjI(4.3) R,IR,IR,I為實數&#xff0c;RRR是實部&#xff0c;III是虛部&#xff0c;j?1j \sqrt{-…

不要迷失在技術的海洋中【轉】

轉自http://www.cnblogs.com/lovecherry/archive/2007/10/28/940555.html 不要迷失在技術的海洋中 技術就好像一片汪洋大海&#xff0c;越深入越望不到邊際。就拿自己的體驗來說吧&#xff0c;2000年的時候在學校搞ASP&#xff0c;覺得網頁開發就是這么簡單&#xff0c;把數據庫…

使用代碼設置Item級的權限(權限總結1)

itle in english:set Item Level Permission for SharePoint (MOSS/WSS) List/Document Library Programmatically 有些時候&#xff0c;我們需要為文檔庫里面某個文件設置特殊的權限&#xff0c;這個權限不繼承自列表權限&#xff0c;當然最簡單的最好是再創建一個列表&#…

echarts 4.0.4怎么下載_怎么讓ECharts的提示框tooltip自動輪播?

1. 怎么讓ECharts的提示框tooltip自動輪播?在用ECharts做大屏或者可視化展示項目的時候&#xff0c;讓提示框tooltip自動輪播是比較常見的需求&#xff0c;給大家推薦一個插件叫echarts-tooltip-auto-show,名字是有點長&#xff0c;但是挺好用的。在hover顯示tooltip之后&…

[React Native]高度自增長的TextInput組件

之前我們學習了從零學React Native之11 TextInput了解了TextInput相關的屬性。 在開發中,我們有時候有這樣的需求, 希望輸入區域的高度隨著輸入內容的長度而增長, 如下&#xff1a; 這時候我們需要自定義一個組件&#xff1a; 在項目中創建AutoExpandingTextInput.js import …

網站開啟Gzip壓縮-apache

找到并打開apache/conf目錄中的httpd.conf文件 httpd.conf中打開deflate_Module和headers_Module模塊&#xff0c;具體做法為將 如下兩句前面的#去掉&#xff1a;LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so 3.配置文…

第4章 Python 數字圖像處理(DIP) - 頻率域濾波3 - 取樣和取樣函數的傅里葉變換、混疊

目錄取樣和取樣函數的傅里葉變換取樣取樣后的函數的傅里葉變換取樣定理混疊由取樣后的數據重建&#xff08;復原&#xff09;函數取樣和取樣函數的傅里葉變換 取樣 fˉ(t)f(t)sΔT(t)∑n?∞∞f(t)δ(t?nΔT)(4.27)\bar f(t) f(t)s_{\Delta T}(t) \sum_{n-\infty}^{\infty}…

[轉]Android開發,實現可多選的圖片ListView,便于批量操作

本文轉自&#xff1a;http://www.cnblogs.com/gergulo/archive/2011/06/14/2080629.html 之前項目需要實現一個可多選的圖片列表&#xff0c;用戶選中一到多張圖片后&#xff0c;批量上傳。但是網上有可多選普通列表的代碼、也有單純圖片列表的代碼&#xff0c;卻沒有兩者合并的…

個人信息安全影響評估指南_發布 | 網絡安全標準實踐指南—移動互聯網應用程序(App)收集使用個人信息自評估指南...

關于發布《網絡安全標準實踐指南—移動互聯網應用程序(App)收集使用個人信息自評估指南》的通知信安秘字[2020] 40號各有關單位&#xff1a;為落實《網絡安全法》相關要求&#xff0c;圍繞中央網信辦、工信部、公安部、市場監管總局聯合制定的《App違法違規收集使用個人信息行為…

Go的50度灰:Golang新開發者要注意的陷阱和常見錯誤

Go的50度灰&#xff1a;Golang新開發者要注意的陷阱和常見錯誤 http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/

android intent和intent action大全

不管是頁面牽轉&#xff0c;還是傳遞數據&#xff0c;或是調用外部程序&#xff0c;系統功能都要用到intent。 在做了一些intent的例子之后&#xff0c;整理了一下intent&#xff0c;希望對大家有用。 由于intent內容太多&#xff0c;不可能真的寫全&#xff0c;難免會有遺落&a…