title: ImageMagick: custom rank filter? Like erode or dilate or median but a different rank, e.g. a 'percentile' filter?
body: <p>When applying a rank filter with ImageMagick such as erode or delate or median, it takes the minimum (<code>erode</code>) or maximum (<code>dilate</code>) or middle (<code>median</code>) value of all pixels within a certain radius or custom shape around each source pixel.</p>
  
  <p>Is it also possible to take a <em>custom rank</em> of the surrounding pixel values? For example when using a 5x5 square, with the <code>erode</code> or <code>dilate</code> or <code>median</code> filters, respectively the lowest, highest, of middle value of the 25 pixels surrounding each pixel is taken. What I'm looking for is a way to take the 8th or 23rd value, for example. </p>
  
  <p>Perhaps this could be expressed as a percentile, e.g. take the 20% percentile value of an arbitrary area surrounding each pixel. Which in case of a 7x7 square would be the 0.2*7*7 = the 9th value out of the total 49 in order.</p>
  
  <p>The <code>erode</code>, <code>dilate</code> and <code>median</code> filters would correspond to the 0%, 100%, and 50% percentiles, respectively. </p>