이 문제에 대한 해킹 사실을 발견했습니다. 필자는 데이터를 반복적으로 필터링하지 않고 2d 그래프의 개별 값에 가중치 값을 다시 할당합니다. 이 가중치는 해당 그래프 위치에 얼마나 많은 필터링을 적용해야하는지 알려줍니다. 이 가중치는 또한 가우시안 필터의 너비 (값이 영향을 미치는 범위)를 알려줍니다. 다음은 그래프 값이 변경 될 때마다 실행해야하는 코드입니다.
vector<float> graph_values(100);
vector<float> graph_weights(100);
vector<float> graph_filtered_values(100);
// temp
vector<float> accumulated_weights(graph_values.size());
for(int x1=0;x1<graph_values.size();x1++)
{
graph_filtered_values[x1] = 0;
for(int x2=x1-30;x2<=x1+30;x2++)
{
float w = expf(-.5*(float)(x2-x1)*(x2-x1)/(graph_weights[x2]*graph_weights[x2]));
if(x2==x1&&!_finite(w))
w = 1;
if(w<0.0001)
w = 0;
graph_filtered_values[x1] += graph_values[x2] * w;
accumulated_weights[x1] += w;
}
}
for(int x1=0;x1<graph_values.size();x1++)
{
graph_filtered_values[x1] /= accumulated_weights[x1];
}
이 알고리즘은 graph_values, graph_weights 및 graph_filtered_values에 대해 3 배의 메모리를 사용합니다. 그래프 값이 더 이상 변경되지 않으면 최종 제품에서 첫 번째 두 배열을 삭제하여이 기능을 최적화 할 수 있습니다.
알아 두어야 할 사항! 감사합니다 – AareP
선형 필터에 대한 답이 맞지만 실제로는 "필터링이라고도하는 다른 항목", 즉 비선형 필터 클래스입니다. – Reunanen