1

I want to implement a ring median filter - what it does is basically replace the center pixel by the median values of the pixels in a circular ring around it. I can make a circular mask of some radius like this

kernel = np.zeros((2*radius+1, 2*radius+1))
y,x = np.ogrid[-radius:radius+1, -radius:radius+1]
mask = x**2 + y**2 <= radius**2
kernel[mask] = 1

Then I can use scipy's generic filter to take median of the values

import scipy.ndimage.filters as scp_filt
circular_median = scp_filt.generic_filter(my_image, np.median, footprint=kernel)

The above mask is including pixels inside the circle. What pixels should lie on the circumference seems slightly ambiguous to me (think of circle inscribed in 3*3, 5*5, 7*7 kernels). Is there a "ring" function I can use OTS or something?

Why all this - trying to use a part of this paper http://pages.swcp.com/~spsvs/resume/PODS_DSS2009_2009-01-15.pdf Ring median filter, after subtraction from the original image leaves objects with a scale size of less than the radius.

Also, not sure if I should do this in RGB or not. I have only seen median filters on grayscale images

madratman
  • 127
  • 2
  • 8
  • You can simply compute the relative coordinates of the ring, and then apply it on you image. It is comparable to apply a custom structuring element in mathematical morphology. – FiReTiTi Apr 26 '16 at 21:14
  • Yes, that's exactly my question - what are the exact relative coordinates. Say if 0,0 is the center of a 11*11 kernel, what are the coordinates of the circle. It's slightly ambiguous, and for that the Bresenham algo (see my answer below) seems good. There's an old question here http://stackoverflow.com/questions/17454931/how-can-i-apply-a-ring-shaped-median-filter-to-an-image-in-matlab which uses a gaussian2D, but for that the condition `ring = ring>eps & ring<1e-9` is manual, and needs to be changed for each kernel size. – madratman Apr 27 '16 at 01:14
  • The easiest way would be before applying the median filter, to compute the ring coordinates. In your case, you can start with the point (0,5), then trace the circle/ring shape with a small step (let's say a degree at a time), but you have to check that the new point is not already into the list. – FiReTiTi Apr 27 '16 at 07:29

1 Answers1

-1

Use the Bresenham algorithm for circles https://www.daniweb.com/programming/software-development/threads/321181/python-bresenham-circle-arc-algorithm

Scipy generic filter along with this ring median kernel is quite slow in practice, at least in python

madratman
  • 127
  • 2
  • 8
  • The wire shape is a chain, not a portion of ellipsis. – FiReTiTi Apr 26 '16 at 21:13
  • Umm, are you referring to the catenary curve here? The idea of subtracting the ring median filter was to keep the elements smaller than the scale of radius(according to the linked paper). Or do you mean in the kernel, the shape of the ring is not correct – madratman Apr 27 '16 at 01:15
  • The ring shape will not match the catenary curve, so the detection will be poor. There is a patent from Thales Helicopter (former Eurocopter) that specifically uses a chain shape in order to match the catenary curve. (PS: I am not the one who down voted...) – FiReTiTi Apr 27 '16 at 07:26
  • That's interesting. Can you please link the patent? Unable to find it. P.S.: No worries :), let them haters hate, heh. – madratman Apr 28 '16 at 02:12
  • Patent from "François-Xavier Filias and Jean Sequeira", but I don't know the number. – FiReTiTi Apr 28 '16 at 07:24