I have been working on implementing Lee Sigma Filter for SAR images.I created a noisy image and filtered it using the code that i have written. But the SSIM value between the non-noisy image and the filtered image comes out too 0.45 only. Can someone help me identify the mistake in my code?
def std(image):
np_img = np.array(image)
d = np.std(np_img)
return d
def sigma(image , k ):
x_pixels,y_pixels=image.shape
new_im = np.zeros((x_pixels,y_pixels), np.uint8)
n_r = k // 2
s = std(image)
for x in range(x_pixels):
for y in range(y_pixels):
total = 0
t = 0
m=0
M=0
int_max = image[x,y] + (2 * s)
int_min = image[x,y] - (2 * s)
for x_i in range(max(0,x -n_r),min(x_pixels-1 , x +n_r) + 1):
for y_i in range(max(0,y -n_r),min(y_pixels-1 , y +n_r) + 1):
t += image[x_i,y_i]
m+=1
if (image[x_i,y_i] >= int_min and image[x_i,y_i] <= int_max):
total += image[x_i,y_i]
M = M + 1
total-=image[x,y]
M-=1
t -= image[x,y]
m-=1
if M >= 3 :
new_im[x, y] = total / M
else :
new_im[x, y] = t / m
return new_im