How can I do, either in ArcGIS, grass or another tool, the following: for each cell (pixel), if there is at least one cell with value '4' in a neighborhood of 5 cells around it, reclassify that cell to 0, otherwise don't change the value? Thanks.
OK I found it through help of an ex-colleague. It is (to me) not intuitive, so I'll explain for any interested readers: using Spatial Analyst, first you reclassify your map into one where all cells with values other than 4 are set to NODATA. Then you make a map with for each cell the majority in the neighborhood (focal statistic with circle neighborhood and 'majority' statistics type). That gives you, in effect, a map that has value 4 for all cells that have another cell with 4 in the neighborhood. Then finally you combine (raster calculator) the original input map with this last map: if the value in the original map is 4; and the corresponding cell in the 'mask' map is also 4; then reclassify to 0, otherwise do nothing.
This also works when you add more than 1 value you want to look for. If you, in the first step, reclassify to a map with more than 1 valid value, you are in effect saying 'reclassify to this value if there are at least one of the given values in the neighborhood, and if there are both, reclassify to that of with the largest amount of cells around it'.
Pretty spiffy :)
After further thinking about this method today, here's another variation that I needed after the question above and that might be useful for people who end up here google'ing: to make a map with for each cell the count of how many cells with a certain value are in the neighborhood, do the following. First reclassify the map into a map with in each cell that has the value you're looking for, the amount of cells in the neighborhood you're investigating (so in the example above but with a neighborhood of 3 to make the example easier, change all cells with value '4' to '8' (3x3 - the centroid)) and all other cells to 0. Then, on that map, do a focal statistic of the average of the neighborhood. This works because e.g. when there are 6 cells in the neighborhood, the average is 6x8/8 = 6.