---
name: "im_rank"
section: "3"
platform: "linux"
package: "libvips-dev"
version: "7.20.7-1+b3"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/im_rank"
---

# im\_rank(3)

rank filter

## NAME

im\_rank, im\_rank\_raw - rank filter

## SYNOPSIS

\#include \<vips/vips.h\>

int im\_rank(in, out, xsize, ysize, n)\
 IMAGE \*in, \*out;\
 int xsize, ysize, n;

int im\_rank\_raw(in, out, xsize, ysize, n)\
 IMAGE \*in, \*out;\
 int xsize, ysize, n;

## DESCRIPTION

**im\_rank()** does rank filtering on an image. A window of size xsize by ysize is passed over the image. At each position, the pixels inside the window are sorted into ascending order and the pixel at the nth position is output. n numbers from 0.

It works for any non-complex image type, with any number of bands.  The input is expanded by copying edge pixels before performing the operation so that the output image has the same size as the input. Edge pixels in the output image are therefore only approximate.

**im\_rank\_raw()** works just as im\_rank(), but does not expand the input.

## EXAMPLES

For a median filter with mask size m (3 for 3x3, 5 for 5x5, etc.) use

   im\_rank( in, out, m, m, m \* m / 2 );

The special cases n == 0 and n == m \* m - 1 are useful dilate and expand  operators.

## RETURN VALUE

The function returns 0 on success and -1 on error.

## SEE ALSO

[im\_conv(3)](/im_conv/3.md), [im\_fastcor(3)](/im_fastcor/3.md).

## COPYRIGHT

1989-1996 The National Gallery and Birkbeck College
