title: Applying even-sized median filter in Python
body: <p>My assignment is to apply a median filter of size 50x50 pixels to an image. I know how to apply the filter, but how can I specify the size of the filter when it is even? My code so far is below.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from astropy.io import fits
  import scipy.signal as sg
  
  #   Open data files
  hdulist = fits.open('xbulge-w1.fits')
  w1data = hdulist[0].data
  
  hdulist2 = fits.open('xbulge-w2.fits')
  w2data = hdulist2[0].data
  
  #   Apply median filter to each image
  w1_med = sg.medfilt(w1data)
  w2_med = sg.medfilt(w2data)
  
  #   Set maximum sampled galactic lat (b) and long (l)
  l_max = 15
  b_max = 15
  
  #   Plot median filtered images, rescaled to galactic coordinates
  plt.subplot2grid((2,1), (0,0))
  plt.imshow(w1_med, origin='lower',
             extent=[l_max, -l_max, -b_max, b_max],
             cmap = 'gray')
  plt.title('W1 median filter')
  
  plt.subplot2grid((2, 1), (1,0))
  plt.imshow(w2_med, origin='lower',
             extent=[l_max, -l_max, -b_max, b_max],
             cmap = 'gray')
  plt.title('W2 median filter')
  
  plt.tight_layout()
  plt.show()
  </code></pre>