Speckle ( Lee Filter) in Python
Question: I am trying to do speckle noise removal in satellite SAR image.I am not
getting any package which does speckle noise removal in SAR image. I have
tried pyradar but it works with python 2.7 and I am working on Anaconda with
python 3.5 on windows. Also Rsgislib is available but it is on Linux. Joseph
meiring has also given a Lee filter code on github but it fails to work. :
<https://github.com/reptillicus/LeeFilter>

Kindly, can anyone share the python script for Speckle Filter or how to
proceed for speckle filter design in python.


Answer: This is a fun little problem. Rather than try to find a library for it, why
not write it from the definition?

    
    
    from scipy.ndimage.filters import uniform_filter
    from scipy.ndimage.measurements import variance
    
    def lee_filter(img, size):
        img_mean = uniform_filter(img, (size, size))
        img_sqr_mean = uniform_filter(img**2, (size, size))
        img_variance = img_sqr_mean - img_mean**2
    
        overall_variance = variance(img)
    
        img_weights = img_variance**2 / (img_variance**2 + overall_variance**2)
        img_output = img_mean + img_weights * (img - img_mean)
        return img_output
    

If you don't want the window to be a square of size x size, just replace
uniform_filter with something else (convolution with a disk, etc)

This seems rather old-fashioned as a filter, it won't behave well at edges.
You may want to look into modern edge-aware denoisers, like guided filter or
bilateral filter.

