cgray = 256*rand(30); % 30x30 random grayscale image image(cgray), colormap gray % display image and set colormap to grayscale crgb = rand(30,30,3); % 30x30(x3) random RGB image image(crgb) % display (colormap has no effect)You create an image by setting values or you can use the command imread to read an existing image. You could create one using Paint and then read it, or you can even read one off the internet:
smokey = imread('http://www.math.utk.edu/~ccollins/UTpicts/ut7.jpg');
image(smokey)
Now for this lab we need square images, so after you read an image, you'll
need to check the size via size, for example size(smokey)
returns 127 149 3 so it is not square. I can either trim it to 127x127:
smokeytrim = smokey(:,1:127,:);You could use other ranges of columns to center the image, but make sure you use exactly 127 (or whatever the smallest dimension is).
function X = catmap(Y)
% applies Arnold's Cat Map to the image Y to produce image X
p = size(Y,1); % get the number of pixels on each side
X = zeros(size(Y)); % make space for X (all zeros to start)
for i = 1:p % loop through all the pixels
for j = 1:p
newi = mod(((i-1) + (j-1)),p) + 1; % get new i coord (m+n) mod p
newj = mod(((i-1) + 2*(j-1)),p) + 1; % get new j coord (m+2n) mod p
X(newi,newj,:) = Y(i,j,:);
end
end
X = uint8(X); % this may have to be adjusted depending on the type of image
To use this function, start with an image, say it is called myimage. Since
we want to apply this function over and over again, we first copy your image
into a temporary variable X to use and then we apply the function over
and over again. We can put this in a loop, have it display the image
and pause so we can see it, like this:
X = myimage; for i = 1:100 X = catmap(X); image(X) pause endFor the trimmed smokey image, I found that it took 128 iterations (instead of 100) to get back to the original image.
Print out your image, a jumbled version of your image (for some intermediate iteration). Tell me the size of your image and the number of iterations it took for it to return to the original.