Rank Transform in Image Processing

8 05 2009

Rank Transform is a form of non-parametric local transform (i.e. relies on the relative ordering of local intensity values, and not on the intensity values themselves) used in image processing to rank the intensity values of the pixels within a square window. The centre pixel’s intensity value is replaced by its rank amongst the neighboring pixels [1].

Advantages

  1. Reduces effects of variations caused by camera’s gain and bias.
  2. Increase in robustness to outliers near depth-discontinuities.

Disadvantages

  1. Loss of information associated with the pixel.
  2. Rank transform cannot distinguish between rotations and reflections, and has been shown to produce the same rank for variety of patterns [2].

Example

Cones  Sample Image-Cones

RankCones3x3Rank Transform (3×3)

RankCones5x5Rank Transform (5×5)
RankCones7x7Rank Transform (7×7) RankCones9x9Rank Transform (9×9) RankCones15x15Rank Transform (15×15)

MATLAB Code

% *************************************************************************
% Title: Function-Rank Transform of a given Image
% Author: Siddhant Ahuja
% Created: May 2008
% Copyright Siddhant Ahuja, 2008
% Inputs: Image (var: inputImage), Window size assuming square window (var:
% windowSize)
% Outputs: Rank Tranformed Image (var: rankTransformedImage), 
% Time taken (var: timeTaken)
% Example Usage of Function: [a,b]=funcRankOneImage('Img.png', 3)
% *************************************************************************
function [rankTransformedImage, timeTaken] = funcRankOneImage(inputImage, windowSize)
% Grab the image information (metadata) using the function imfinfo
imageInfo=imfinfo(inputImage);
% Since Rank Transform is applied on a grayscale image, determine if the
% input image is already in grayscale or color
if(getfield(imageInfo,'ColorType')=='truecolor')
% Read an image using imread function, convert from RGB color space to
% grayscale using rgb2gray function and assign it to variable inputImage
    inputImage=rgb2gray(imread(inputImage));
else if(getfield(imageInfo,'ColorType')=='grayscale')
% If the image is already in grayscale, then just read it.        
        inputImage=imread(inputImage);
    else
        error('The Color Type of Input Image is not acceptable. Acceptable color types are truecolor or grayscale.');
    end
end
% Check the size of window to see if it is an odd number.
if (mod(windowSize,2)==0)
    error('The window size must be an odd number.');
end
% Initialize the timer to calculate the time consumed.
tic;
% Find the size (columns and rows) of the image and assign the rows to
% variable nr, and columns to variable nc
[nr,nc] = size(inputImage);
% Create an image of size nr and nc, fill it with zeros and assign
% it to variable rankTransformedImage
rankTransformedImage = zeros(nr,nc);
% Find out how many rows and columns are to the left/right/up/down of the
% central pixel based on the window size
R= (windowSize-1)/2;
for (i=R+1:1:nr-R) % Go through all the rows in an image (minus R at the borders)
    for (j=R+1:1:nc-R) % Go through all the columns in an image (minus R at the borders)     
        rank = 0; % Initialize default rank to 0
        for (a=-R:1:R) % Within the square window, go through all the rows
            for (b=-R:1:R) % Within the square window, go through all the columns
                % If the intensity of the neighboring pixel is less than
                % that of the central pixel, then increase the rank
                if (inputImage(i+a,j+b) < inputImage(i,j))
                    rank=rank+1;
                end     
            end
        end
        % Assign the rank value to the pixel in imgTemp
        rankTransformedImage(i,j) = rank;
    end
end
% Stop the timer to calculate the time consumed.
timeTaken=toc;

In order to run the above code, you should have the image processing toolbox installed in MATLAB.

Experiment with Varying Patterns

 

TestPattern1

Test Pattern 1

 

TestPattern2

Test Pattern 2

 

TestPattern3

Test Pattern 3

 

TestPattern4

Test Pattern 4

 

TestPattern5

Test Pattern 5

 

TestPattern6

Test Pattern 6

 All of the above patterns yield  the following rank result:

TestPatternRankResult

with a rank of 4.

Thus proving that Rank transform cannot distinguish between rotations and reflections, and has been shown to produce the same rank for variety of patterns [2]. More of these patterns can be generated to emphasize the point.

References

[1] R. Zabih and J. Woodfill, “Non-parametric Local Transforms for Computing Visual Correspondence”, ECCV 2004, pp. 151-158

[2] J. Banks, P. Corke, “Quantitative Evaluation of Matching Methods and Validity Measures for Stereo Vision”, IJRR, 2001; 20; 512

R. Zabih and J. Woodfill, “Non-parametric Local
Transforms for Computing Visual Correspondence”, ECCV
2004, pp. 151-158







Follow

Get every new post delivered to your Inbox.

Join 85 other followers