I'm trying to write a notebook that can take any square input image, and apply a cat map to it a specified number of times. I've written a pretty simple script that seems to work:
SetDirectory[NotebookDirectory[]];
M = {{1, 1}, {1, 2}};
CatMap[M_, x_, y_, n_, m_] := Mod[MatrixPower[M, m].{x, y}, n]
image = Import["cat1.jpg"];
n = ImageDimensions[image][[1]];
ImageResize[
ImageTransformation[image, CatMap[M, #[[1]], #[[2]], n, 40] &,
DataRange -> Full], 300]
The image looks fine for a few iterations, but at some point, I just see a pattern of black and grey pixels. This demonstration has it working properly, but I can't figure out why that script works and mine doesn't. Here's the relevant code from the demonstration:
catMap = Compile[{{pic, _Integer, 2}},
Table[pic[[Mod[x + y, 100, 1], Mod[x + 2 y, 100, 1]]], {x,
100}, {y, 100}]];poincarepic = 255 - Reverse[
poincarepic = 255 - Reverse[(*image pasted here*)[[1, 1]]];
Manipulate[
ArrayPlot[Nest[catMap, poincarepic, iter],
Frame -> False], {{iter, 1, "iterations"}, 0, 150, 1,
Appearance -> "Labeled"}, SaveDefinitions -> True]
Any help would be greatly appreciated!