I would like to denoise some data using wavelet filters. My current approach is to employ the stationary wavelet transform with Haar wavelets.
However, this leads to undesirable artifacts at the top and bottom boundary of the dataset, as you can see in the figure. Is there a clever way to suppress these artifacts?
I am especially interested in removing the initial drop of the raised profile after the wavelet filter.
The code to generate the figure is:
sigma[y_] := 0.03 + y;
box[x_] := Piecewise[{{1.0, -0.5 <= x <= 0.5}, {0, True}}]
crossx[w_] := box[w];
dataMax = MovingAverage[#, 10] & /@ MovingAverage[#, 5] &@ Table[crossx[x/sigma[y]], {x, -1, 1, 0.01}, {y, 0, 1.0, 0.01}];
dataMin = Map[Max[# - 0.4, 0.] &, dataMax, {2}];
{ni, nj} = Dimensions[dataMin];
data = Table[RandomReal[{dataMin[[i, j]], dataMax[[i, j]]}], {i, 1, ni}, {j, 1, nj}];
img = Image[Transpose[data]];
wvt = StationaryWaveletTransform[img, HaarWavelet[], 4];
wvfilter = WaveletMapIndexed[ImageMultiply[#, 0] &, wvt, {___, 1 | 2 | 3}];
iwvt = InverseWaveletTransform[wvfilter];
ops = {PlotRange -> {0, 1}, ViewPoint -> {-2.53, -1.27, 1.86}, ImageSize -> 400, ColorFunction -> "TemperatureMap"};
p1 = ListPlot3D[dataMin, Evaluate[ops], PlotLabel -> "clean dataset"];
p2 = ListPlot3D[data, Evaluate[ops], PlotLabel -> "noisy dataset"];
p3 = ListPlot3D[Transpose[ImageData[iwvt][[1 ;; -1]]], Evaluate[ops],PlotLabel -> "dataset after wavelet"];
p = Grid[{{p1, p2, p3}}]
Export[FileNameJoin[{$HomeDirectory, "Desktop",
"wavelet_filter_test.png"}], p];