quickMedian

Syntax

int quickMedian(int low, int high)

Arguments

low
lowest put/get cell that contains values, usually zero.
high
highest put/get cell that contains values, usually calculated as (radius*2+1) * (radius*2+1)

Return

The return value is the median value.

Description

Finds the median value within the given range of put/get cells.

Comments

Please notice that quickMedian works fast for radius values from 1 to 8, but above that it gets very slow. There are much faster algorithms that use tables or histogram for calculating median values with a high radius. There are also slightly faster algorithms for medians with a radius of 1 or 2.

Example

%ffp
ctl(7): "Radius", range=(1,15), val=1, page=1
ForEveryTile:
{
  for (y=y_start; y < y_end; y++)
    for (x=x_start; x < x_end; x++)
      for (z=0; z < 3; z++) {
        quickFill(x,y,z,0,ctl(7),0,0,X,Y);
        pset(x,y,z,quickMedian(0,(ctl(7)*2+1)*(ctl(7)*2+1)-1));
  }
  return true;
}

See Also

quickFill