A neighborhood transformation stage is designed to perform filtering operations on an image matrix. A group of pixel values in the image matrix are accessed. A series of comparators are used to compare the values of neighboring pixels with the value of a given pixel in the group. The outputs of the comparators are combined to form a vector to address a programmable look-up table. The addressed output of the look-up table is used as a control signal for a selector which either maintains the value of the given pixel or transforms it into another value associated with a neighboring pixel whose value has been ranked in a predetermined order by a rank sorter device used to compare the values of the neighboring pixels with each other.