图像像素灰度处理代码
生活随笔
收集整理的這篇文章主要介紹了
图像像素灰度处理代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
圖像像素灰度處理
- 1.計算某行相鄰像素的灰度變化率
1.計算某行相鄰像素的灰度變化率
a=img[:,100] def normalization(value): # """標準化 # 公式:(原始值-均值)/方差 # :return 范圍任意,標準化后數據均值為0,標準差為1 # """new_value = (value - value.mean()) / value.std()return new_value b=normalization(a)#畫出灰度曲線 import matplotlib.pyplot as plt values = range(0,len(a),1) gray = a plt.plot(values, gray, linewidth=2) plt.title("gray Number",fontsize=14) plt.xlabel("Value", fontsize=14) plt.ylabel("gray of Value", fontsize=14) # plt.tick_params(axis='x', labelsize=10) # plt.axis([0, 6, 0, 30]) plt.show() #計算一階微分 import matplotlib.pyplot as plt list_with_diff = [] for n in range(1, len(lista)):list_with_diff.append(lista[n] - lista[n-1]) # print("Difference between adjacent elements in the list: \n", # list_with_diff) #計算一階微分變化率 import matplotlib.pyplot as plt list_with_diff = [] for n in range(1, len(lista)):list_with_diff.append(abs((lista[n] - lista[n-1])/lista[n] )) # print("Difference between adjacent elements in the list: \n", # list_with_diff)#畫出一階微分曲線 c = list_with_diff import matplotlib.pyplot as plt values = range(0,len(c),1) gray = c plt.plot(values, gray, linewidth=2) plt.title("gray Number",fontsize=14) plt.xlabel("Value", fontsize=14) plt.ylabel("gray of Value", fontsize=14) # plt.tick_params(axis='x', labelsize=10) # plt.axis([0, 6, 0, 30]) plt.show()計算峰值
from scipy.signal import find_peaks# x is the vector from which you want to extract the peaks c = np.array(c) peaks, _ = find_peaks(c,height=0.05) plt.plot(c) plt.plot(peaks, c[peaks], "x")總結
以上是生活随笔為你收集整理的图像像素灰度处理代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 常用告警屏蔽项
- 下一篇: 论文笔记:Extendability f