S-G濾波之包絡濾波
阿新 • • 發佈:2021-01-24
由於遙感觀測總是受到雲層,大氣影響,總會造成植被指數驟降問題,包絡濾波的就是根據植被的特性,將驟降值認為是錯誤值,選擇最大值進行濾波
SG濾波程式碼參考&後來&部落格
定義濾波函式
import pandas as pd
import matplotlib.pyplot as plt
#%% SG_filter
import numpy as np
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
def sgoal_filter (data,window_size,order):
if window_size == None:
window_size = int(len(data)) // 10
if window_size % 2 == 0 or window_size == 0:
window_size += 1
arr = []
step = int((window_size-1)/2)
for i in range(window_size):
a = []
for j in range(order) :
y_val = np.power(-step + i, j)
a.append(y_val)
arr.append(a)
arr = np.mat(arr)
arr = arr * (arr.T * arr).I * arr.T
a = np.array(arr[step])
a = a.reshape(window_size)
data = np.insert(data, 0, [data[0] for i in range(step)])
data = np.append(data, [data[-1] for i in range(step)])
qlist = []
for i in range(step, data.shape[0] - step):
arra = []
for j in range(-step, step+1):
arra.append(data[i +j])
b = np.sum(np.array(arra) * a)
qlist.append(b)
return qlist
ndvi[‘MCD15A3H_006_ndvi_500m’]濾波前圖片
initial = np.array(ndvi['MCD15A3H_006_ndvi_500m'])
sg_1 = np.array(data_sg)
dev = initial-sg_1
stad = np.sqrt(np.mean(dev**2))
while stad > 0.08:
for i in range(len(sg_1)):
if dev[i] >0:
sg_1[i] = initial[i]
initial = sg_1
sg_1 = np.array(sgoal_filter(sg_1,3,1))
dev = initial-sg_1
stad = np.sqrt(np.mean(dev**2))
fig, axes = plt.subplots()
axes.plot(ndvi.Date, sg_1)
axes.plot(ndvi.Date, np.array(ndvi['MCD15A3H_006_Lai_500m']))
結果