Message Boards Message Boards

1
|
4804 Views
|
5 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Keep zero values using GaussianFilter[ ]?

Hi,

Is there a way to preserve zero values when we use a filter command?

data = {12.76`, 7.68`, 13.85`, 4.5`, 2.32`, 3.64`, 2.18`, 2.72`, 
   1.62`, 0.0`, 18.09`, 12.28`, 18.`, 9.76`, 8.16`, 0.0`, 21.41`, 
   0.53`, 4.7`, 0.81`, 11.44`, 4.36`, 15.58`, 20.17`, 7.48`, 3.67`, 
   2.73`, 8.66`, 4.82`, 0.84`, 4.04`, 39.19`, 0.18`, 1.76`, 3.35`, 
   10.79`, 11.85`, 7.1`, 0.58`, 2.84`, 3.68`};

GraphicsRow[{ListLinePlot[data], 
  ListLinePlot[GaussianFilter[data, 1.5], PlotRange -> All]}]

enter image description here

POSTED BY: M.A. Ghorbani
5 Replies
Posted 3 years ago

You could record zeros, apply a gaussian filter, than replace the areas in the dataset which were previously zeros.

Isn't that the same as this from my answer?

GaussianFilter[data, 1.5] // ReplacePart[#, Position[data, 0.0] -> 0.0] &
POSTED BY: Rohit Namjoshi
Posted 3 years ago

You could record zeros, apply a gaussian filter, than replace the areas in the dataset which were previously zeros.

POSTED BY: louis sarwal

Thank you so much, Henrik and Rohit.

POSTED BY: M.A. Ghorbani
Posted 3 years ago

Or if you want to preserve only the zero values

GaussianFilter[data, 1.5] // ReplacePart[#, Position[data, 0.0] -> 0.0] &
POSTED BY: Rohit Namjoshi

Dear Mohammad,

I guess it depends on what you basically want to achieve using GaussianFilter. A very simple way to preserve the zeros would be to use the respective minimum of the data and the filtered data:

filteredData = GaussianFilter[data, 1.5];
mindata = Min /@ Transpose[{data, filteredData}];
ListLinePlot[{data, filteredData, mindata}, PlotStyle -> {Dashed, Black, {Thick, Red}}, PlotRange -> All, ImageSize -> Large]

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract