user2678163
user2678163

Reputation: 21

How to implement the arnold transform of image

I need to implement the arnold transformation on colour image as it is part of my project please suggest how to implement it for MxN image

Upvotes: 0

Views: 2369

Answers (1)

Tamás Zahola
Tamás Zahola

Reputation: 9311

In the classical sense, the continuous Arnold's map is defined on the unit square, and therefore the discrete version is defined on square images:

Consider your image as three NxN matrices; one NxN matrix for each colour channel (assuming you're working with RGB images). Do the following transformation with each of the matrices:

Map the (i,j) element of the input matrix to the ((i + j) mod N, (i + 2j) mod N) element of the output matrix.

It's a concatenation of a vertical and a horizontal shearing transformation, "wrapped around" to the original image rectangle:

Arnold map

(the image is from the corresponding Wikipedia article)

In pseudocode for a single colour channel:

Image arnold(inputImage){
    outputImage = Image(inputImage.width, inputImage.height);

    for(x = 0; x < inputImage.width; x++){
        for(y = 0; y < inputImage.height; y++){
            pixel = inputImage[x][y];
            outputImage[(2*x + y) mod inputImage.width][(x + y) mod inputImage.height] = pixel;
        }
    }
    return outputImage;
}

(note that conventionally we index matrices by (row,column) and images by (column,row))

So that's for square (NxN) images. What you want (Arnold's map for MxN images, where possibly M != N) is somewhat ill-posed in the sense that it's not clear whether it preserves some interesting properties of Arnold's map. However, if that doesn't bother you, you can generalize the map for MxN images the following way:

  1. Perform a vertical shear with wrap-around in such a way, that the j-th column is circulalry shifted upward by j*M/N (note that this leaves the first column and the last column in-place) *
  2. Perform a horizontal shear with wrap-around in such a way, that the i-th row is circulalry right-shifted by i*N/M (this leaves the first and the last row in-place) *

* : shearing is simply shifting columns/rows

Edit: updated my answer for the generalized MxN case

Upvotes: 1

Related Questions