Removing outliers from region

Dear all,

What I am trying to do is, given a specific clip/slice, remove the data which has a very high value and very low frequency. I tried implementing in python some kind of “dynamic” condition for the threshold but it’s hard to find a specific correlation in my dataset. Is there a way to automatically filter out outliers from a specific region (eg. clip)? Reading through the documentation I saw the median filter, but I am not sure if that is the right one for the job, as it technically changes every value in the field instead of cutting off the outliers