TransWikia.com

My 3x3 Weighted Median Filter doesn't seem to be improving my image quality

Signal Processing Asked by Mr. Johnny Doe on January 15, 2021

In order to reduce noise in my training dataset,I attempted a WMF whose weights are shown in a 2-D array as follows(values finally get normalized by division by 15:

[1 , 2 , 1
 2 , 3 , 2
 1 , 2 , 1]

My input image is an RGB image size (128,128,3). The pixel values are integers in the range of 0-255.

Isolation of each of my three channels is done as:

X_R=X_dummy[:,:,0]
X_G=X_dummy[:,:,1]
X_B=X_dummy[:,:,2]
R_padded=np.pad(X_R,[mask_start,mask_start],'symmetric')
G_padded=np.pad(X_B,[mask_start,mask_start],'symmetric')
B_padded=np.pad(X_G,[mask_start,mask_start],'symmetric')

Where mask_start=2

Convolution for a single channel is shown as:

for x in range(mask_cent,row_pad-mask_start):#The upper limit thing is not included. So Highest value is row_pad-mask_start-1
    for y in range(mask_cent,col_pad-mask_start):#These loops seem to be fine
      patch_selected_R = R_padded[x - mask_start-1: x + mask_start, y - mask_start-1: y + mask_start]
      a1_R= W*patch_selected_R
      med=np.median(a1_R)
      med=med*15
      b[x,y,0]=med

My images, which are shown below look like a colour correction rather than a denoising:

the original image

The resulting image

I am unsure of what is going wrong right now.

Edit: Something went wrong, this is my imgur link
https://imgur.com/gallery/1d4V5vr

Edit 2: new code, its resulting output is available through this link

https://imgur.com/Dr9K1bU
:

a1_R=patch_selected_R
      for i in range(1,2):
        a1_R=np.append(a1_R,patch_selected_R[0,1])
        a1_R=np.append(a1_R,patch_selected_R[1,0])
        a1_R=np.append(a1_R,patch_selected_R[1,2])
        a1_R=np.append(a1_R,patch_selected_R[2,2])
      for i in range(1,3):
        a1_R=np.append(a1_R,patch_selected_R[1,1])
      b[x,y,0]=np.median(a1_R)

2 Answers

Median filters are non-linear systems which do not posses impulse responses, hence the weights that you mention are not related with the median operation.

Those coefficients you presented define just a basic LTI lowpass filter. And it will do its best to remove some high frequency noise. That's it.

Answered by Fat32 on January 15, 2021

Apparently, you intend to weight the patch pixel per pixel in:

a1_R= W*patch_selected_R

and then apply a median on the piece-wise product, and divide by 15. By the way, beware of the * product and the input type of the array, you don't want a matrix product.

This is not the weighted median I know of. To me, the elements in patch_selected_R should be duplicated, triplicated, $n$-plicated with respect to the corresponding integer weight in the mask. On a smallest example: if $w=[1,3,1]$ and $m=[1 4 3]$, the intermediate (longer, of length $1+3+1=5$) buffer is (before sorting):

$$b=[1,4,4,4,3]$$

thus $[1,3,4,4,4]$ after sorting, and the weighted median is $4$ (instead of $3$ with the classical median).

The resulting array here is indeed 15 times larger, and you then compute the median, and replace the central value, with no need to further divide by 15. I am thinking of an interpretation of your result. Meanwhile, the theoretical origin of the weighted median is describe here: What is the advantage of weighted median filter over median filter?

Note: there are combinations of linear and nonlinear filters, like the mean-medians filters.

Answered by Laurent Duval on January 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP