Nov 9, 2010

Histogram smoothing with erosion

The idea of using erosion for smoothing histogram is actually borrowed from the realm of artificial terrain generation where it is a common practice. Recent experiments shows this is a better approach then using polynomial fit. Histogram is a one dimensional height map, after all. The result (smoothed histogram) closely follows the actual data points most of the time and structural property like rises and falls are well preserved.

The procedure is pretty straight forward, replace each entry in the vector containing the histogram with mean of that entry along with n entries backwards n entries forward. Boundary case arises when the index of the current entry is bellow n or beyond length_of_vector-n, I chose to keep those entries unchanged.

result = arr ;

for i=n+1:length(arr)-n
for j=i-n:i+n
sum = sum + arr(j) ;
result(i) = sum/(2*n+1);

No comments:

Post a Comment