第5章 Python 數字圖像處理(DIP) - 圖像復原與重建7 - 周期噪聲 余弦噪聲生成方法

標題

      • 周期噪聲

周期噪聲

周期噪聲通常是在獲取圖像期間由電氣或機電干擾產生的

def add_sin_noise(img, scale=1, angle=0):"""add sin noise for imageparam: img: input image, 1 channel, dtype=uint8param: scale: sin scaler, smaller than 1, will enlarge, bigger than 1 will shrinkparam: angle: angle of the rotationreturn: output_img: output image is [0, 1] image which you could use as mask or any you want to"""height, width = img.shape[:2]  # original image shape# convert all the angleif int(angle / 90) % 2 == 0:rotate_angle = angle % 90else:rotate_angle = 90 - (angle % 90)rotate_radian = np.radians(rotate_angle)    # convert angle to radian# get new image height and widthnew_height = int(np.ceil(height * np.cos(rotate_radian) + width * np.sin(rotate_radian)))new_width = int(np.ceil(width * np.cos(rotate_radian) + height * np.sin(rotate_radian))) # if new height or new width less than orginal height or width, the output image will be not the same shape as input, here set it rightif new_height < height:new_height = heightif new_width < width:new_width = width# meshgridu = np.arange(new_width)v = np.arange(new_height)u, v = np.meshgrid(u, v)# get sin noise image, you could use scale to make some difference, better you could add some shift
#     noise = abs(np.sin(u * scale))noise = 1 - np.sin(u * scale)# here use opencv to get rotation, better write yourself rotation functionC1 = cv2.getRotationMatrix2D((new_width/2.0, new_height/2.0), angle, 1)new_img = cv2.warpAffine(noise, C1, (int(new_width), int(new_height)), borderValue=0)# ouput image should be the same shape as input, so caculate the offset the output image and the new image# I make new image bigger so that it will cover all output imageoffset_height = abs(new_height - height) // 2offset_width = abs(new_width - width) // 2img_dst = new_img[offset_height:offset_height + height, offset_width:offset_width+width]output_img = normalize(img_dst)return output_img 
def spectrum_fft(fft):"""return FFT spectrum"""return np.sqrt(np.power(fft.real, 2) + np.power(fft.imag, 2))
# 周期噪聲
img_ori = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH05/Fig0507(a)(ckt-board-orig).tif', 0) #直接讀為灰度圖像# 正弦噪聲
noise = add_sin_noise(img_ori, scale=0.35, angle=-20)
img = np.array(img_ori / 255, np.float32)
img_noise = img + noise
img_noise = np.uint8(normalize(img_noise)*255)# 頻率域中的其他特性
# FFT
img_fft = np.fft.fft2(img_noise.astype(np.float32))
# 中心化
fshift = np.fft.fftshift(img_fft)            # 將變換的頻率圖像四角移動到中心
# 中心化后的頻譜
spectrum_fshift = spectrum_fft(fshift)
spectrum_fshift_n = np.uint8(normalize(spectrum_fshift) * 255)# 對頻譜做對數變換
spectrum_log = np.log(1 + spectrum_fshift)plt.figure(figsize=(15, 10))
plt.subplot(121), plt.imshow(img_noise, 'gray'), plt.title('With Sine noise'), plt.xticks([]),plt.yticks([])
plt.subplot(122), plt.imshow(spectrum_log, 'gray'), plt.title('Spectrum'), plt.xticks([]),plt.yticks([])
# 在圖像上加上箭頭
plt.arrow(180, 180, 25, 30, width=5,length_includes_head=True, shape='full')
plt.arrow(285, 265, -25, -30, width=5,length_includes_head=True, shape='full')
plt.tight_layout()
plt.show()

在這里插入圖片描述

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

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

相關文章

python寫文字方法_Transcrypt: 用Python寫js的方法

Transcrypt是一個很有意思的工具&#xff1a; 它讓你告別手寫繁復的JavaScript代碼&#xff0c;使用相對簡明清晰的Python代替這一工作。 之后使用這個工具&#xff0c;可以把Python編寫的代碼轉換成JavaScript。 1. 為什么不直接寫JavsScript? JavaScript本身不算是很難的編程…

第5章 Python 數字圖像處理(DIP) - 圖像復原與重建8 - 估計噪聲參數

標題估計噪聲參數估計噪聲參數 周期噪聲的參數通常是通過檢測圖像的傅里葉譜來估計的。 只能使用由傳感器生成的圖像時&#xff0c;可由一小片恒定的背景灰度來估計PDF的參數。 來自圖像條帶的數據的最簡單用途是&#xff0c;計算灰度級的均值和方差。考慮由SSS表示的一個條…

python 隨機獲取數組元素_Python創建二維數組的正確姿勢

List &#xff08;列表&#xff09;是 Python 中最基本的數據結構。在用法上&#xff0c;它有點類似數組&#xff0c;因為每個列表都有一個下標&#xff0c;下標從 0 開始。因此&#xff0c;我們可以使用 list[1] 來獲取下標對應的值。如果我們深入下列表的底層原理&#xff0c…

Qt學習筆記1

1.Qt引用API時&#xff0c;QString到LPCWSTR的轉換&#xff1a; ::GetPrivateProfileIntW(QString(tr("相關設置")).utf16(),QString(tr("時間間隔")).utf16(),5,filePath.utf16())); 2.引用LPRECT時&#xff1a; RECTappRect; ::GetWindowRect(AppWnd,(LP…

在ubunut下使用pycharm和eclipse進行python遠程調試

我比較喜歡Pycharm&#xff0c;因為這個是JetBrains公司出的python IDE工具&#xff0c;該公司下的java IDE工具——IDEA&#xff0c;無論從界面還是操作上都甩eclipse幾條街&#xff0c;但項目組里有些人使用eclipse比較久了&#xff0c;一時讓他們轉pycharm比較困難&#xff…

CSS:頁腳緊貼底部

2019獨角獸企業重金招聘Python工程師標準>>> 我的練習來源于《CSS揭秘》這本書第7章-41緊貼底部的頁腳這部分內容以及書中提到的鏈接。 方案一 描述&#xff1a;以下方案簡單、干凈、現代并且沒有hack&#xff0c;適用于IE8, Chrome, Firefox, Opera等瀏覽器&#x…

第5章 Python 數字圖像處理(DIP) - 圖像復原與重建9 - 空間濾波 - 均值濾波器 - 算術平均、幾何平均、諧波平均、反諧波平均濾波器

標題只存在噪聲的復原 - 空間濾波均值濾波器算術平均濾波器幾何均值濾波器諧波平均濾波器反&#xff08;逆&#xff09;諧波平均濾波器只存在噪聲的復原 - 空間濾波 僅被加性噪聲退化 g(x,y)f(x,y)η(x,y)(5.21)g(x, y) f(x, y) \eta(x, y) \tag{5.21}g(x,y)f(x,y)η(x,y)(5…

librosa能量_librosa與python_speech_features

在語音識別領域&#xff0c;比較常用的兩個模塊就是librosa和python_speech_features了。最近也是在做音樂方向的項目&#xff0c;借此做一下筆記&#xff0c;并記錄一些兩者的差別。下面是兩模塊的官方文檔LibROSA - librosa 0.6.3 documentation?librosa.github.ioWelcome t…

java Unicode轉碼

1 //中文轉UNICODE2 public static String chinaToUnicode(String str) {3 String result "";4 for (int i 0; i < str.length(); i) {5 int chr1 (char) str.charAt(i);6 if (chr1 > 19968 && ch…

oracle-備份工具exp-imp

雖然是按照用戶的方式導出的&#xff0c;但導入之前&#xff0c;還是必須要有相同的用戶存在&#xff0c;刪除用戶以后&#xff0c;是無法進行導入的 --重新創建回zlm用戶 SQL> create user zlm identified by zlm; 盡管zlm用戶的默認表空間是USERS&#xff0c;但是用imp導入…

繼承String?

不能繼承&#xff0c;因為 public final class String extends Objectimplements Serializable, Comparable<String>, CharSequence final修飾的類是不能被繼承的轉載于:https://www.cnblogs.com/crane-practice/p/3666006.html

python中字典數據的特點_Python數據類型(字典)

Python 字典(Dictionary) 字典是另一種可變容器模型&#xff0c;且可存儲任意類型對象。 字典的每個鍵值(key>value)對用冒號(:)分割&#xff0c;每個對之間用逗號(,)分割&#xff0c;整個字典包括在花括號({})中 ,格式如下所示&#xff1a; d {key1: value1, key2: value2}…

第5章 Python 數字圖像處理(DIP) - 圖像復原與重建10 - 空間濾波 - 統計排序濾波器 - 中值、最大值、最小值、中點、修正阿爾法均值濾波器

標題統計排序濾波器中值、最大值、最小值、中點 濾波器修正阿爾法均值濾波器統計排序濾波器 中值、最大值、最小值、中點 濾波器 f^(x,y)median{g(r,c)}(5.27)\hat{f}(x, y) \text{median} \{g(r,c)\} \tag{5.27}f^?(x,y)median{g(r,c)}(5.27) f^(x,y))max{g(r,c)}(5.28)\ha…

如何設置坐標原點值_氨氣檢測儀電化學原理及報警值如何設置

氨氣體檢測儀檢定規程&#xff1a;一般氨氣體檢測儀檢定規程主要是針對技術參數設定的一些標準&#xff0c;具體包含有規程的名稱和范圍、儀器示值誤差、充分性標準差、響應時間、穩定性、報警功能、流量控制器、檢定項目表、檢定操作有數值誤差、重復性、響應時間、穩定性等。…

統計信息及相關說明

統計信息&#xff1a;0 recursive calls20434 db block gets 317970511 consistent gets 0 physical reads 3759764 redo size 382 bytes sent via SQL*Net to client 1061 bytes received via SQL*Net from client 3 SQL*Ne…

Android橫豎屏切換的生命周期

關于Android手機橫豎屏切換時Activity的生命周期問題&#xff0c;網上有很多相似的文章&#xff0c;大多數都是說明在豎屏切換橫屏時Activity會重啟一次&#xff0c;而在橫屏切換豎屏時Activity會重啟兩次。 我本身不太理解這樣設計的意義&#xff0c;并且覺得新版本會解決這個…

python 隨機字符串_python生成隨機數、隨機字符串

python生成隨機數、隨機字符串 import random import string # 隨機整數&#xff1a; print random.randint(1,50) # 隨機選取0到100間的偶數&#xff1a; print random.randrange(0, 101, 2) # 隨機浮點數&#xff1a; print random.random() print random.uniform(1, 10) # 隨…

ACM 會場安排問題

會場安排問題 時間限制&#xff1a;3000 ms | 內存限制&#xff1a;65535 KB難度&#xff1a;4描述學校的小禮堂每天都會有許多活動&#xff0c;有時間這些活動的計劃時間會發生沖突&#xff0c;需要選擇出一些活動進行舉辦。小劉的工作就是安排學校小禮堂的活動&#xff0c;…

第5章 Python 數字圖像處理(DIP) - 圖像復原與重建11 - 空間濾波 - 自適應濾波器 - 自適應局部降噪、自適應中值濾波器

標題自適應濾波器自適應局部降噪濾波器自適應中值濾波器自適應濾波器 自適應局部降噪濾波器 均值是計算平均值的區域上的平均灰度&#xff0c;方差是該區域上的圖像對比度 g(x,y)g(x, y)g(x,y)噪聲圖像在(x,y)(x, y)(x,y)處的值 ση2\sigma_{\eta}^2ση2? 為噪聲的方差&am…

關閉防火墻_從零開始學Linux運維|09.關閉防火墻和SElinux

firewalld是centos7默認的防火墻安全增強型 Linux(Security-Enhanced Linux)簡稱 SELinux初學者建議先關閉,等熟悉了之后再來使用前期聯系中的好多錯誤都有可能是由于沒有關閉或者正確配置上面兩項造成的1.臨時關閉centos7下的防火墻firewalld一行命令就能夠關閉firewalld--&qu…