% Problem 1
load clown
who

Your variables are:

X        map      
caption  

size(X)

ans =

   200   320

size(map)

ans =

    81     3

map

map =

         0         0         0
    0.1250         0         0
    0.1250         0    0.1250
    0.2891         0         0
    0.2891         0    0.1250
    0.1250    0.1250         0
    0.4141         0         0
    0.1250    0.1250    0.1250
    0.2891    0.1250         0
    0.5781         0         0
    0.2891    0.1250    0.1250
    0.4141    0.1250         0
    0.7031         0         0
    0.4141    0.1250    0.1250
    0.5781    0.1250         0
    0.5781    0.1250    0.1250
    0.2891    0.2891    0.1250
    0.7031    0.1250         0
    0.2891    0.2891    0.2891
    0.4141    0.2891         0
    0.7031    0.1250    0.1250
    0.4141    0.2891    0.1250
    0.4141    0.2891    0.2891
    0.8672    0.1250         0
    0.4141    0.2891    0.4141
    0.5781    0.2891         0
    0.8672    0.1250    0.1250
    0.5781    0.2891    0.1250
    0.5781    0.2891    0.2891
    0.7031    0.2891         0
    0.7031    0.2891    0.1250
    0.4141    0.4141    0.2891
    0.7031    0.2891    0.2891
    0.4141    0.4141    0.4141
    0.5781    0.4141    0.1250
    0.8672    0.2891    0.1250
    0.5781    0.4141    0.2891
    0.7031    0.4141         0
    0.8672    0.2891    0.2891
    0.5781    0.4141    0.4141
    0.7031    0.4141    0.1250
    0.7031    0.4141    0.2891
    0.8672    0.4141         0
    0.8672    0.4141    0.1250
    0.8672    0.4141    0.2891
    0.5781    0.5781    0.2891
    0.9961    0.4141    0.1250
    0.5781    0.5781    0.4141
    0.7031    0.5781    0.1250
    0.9961    0.4141    0.2891
    0.5781    0.5781    0.5781
    0.7031    0.5781    0.2891
    0.9961    0.4141    0.4141
    0.7031    0.5781    0.4141
    0.8672    0.5781         0
    0.8672    0.5781    0.1250
    0.7031    0.5781    0.5781
    0.8672    0.5781    0.2891
    0.9961    0.5781         0
    0.8672    0.5781    0.4141
    0.9961    0.5781    0.1250
    0.7031    0.7031    0.2891
    0.9961    0.5781    0.2891
    0.9961    0.5781    0.4141
    0.7031    0.7031    0.5781
    0.7031    0.7031    0.7031
    0.8672    0.7031    0.2891
    0.8672    0.7031    0.4141
    0.9961    0.7031    0.1250
    0.8672    0.7031    0.5781
    0.8672    0.7031    0.7031
    0.9961    0.7031    0.4141
    0.9961    0.7031    0.5781
    0.8672    0.8672    0.7031
    0.8672    0.8672    0.8672
    0.9961    0.8672    0.5781
    0.9961    0.8672    0.7031
    0.9961    0.8672    0.8672
    0.9961    0.9961    0.7031
    0.9961    0.9961    0.8672
    0.9961    0.9961    0.9961

imagesc(X)
colormap(map)


% Problem 2
max(X(:))

ans =

    81

min(X(:))

ans =

     1

     
% Problem 3     
image(X+55)
colormap(gray)

% 55 is added to the color index of the pixel (i,j), i.e X(i,j) - > X(i,j)+55 
% if X(i,j)+55 > 81 the pixel is white. Thus large part o the image have gone white

% Problem 4

imagesc(X(90:160,20:120))
colormap(map)

% Problem 5
imagesc(X(200:(-1):1,:))
colormap(map)

% or 

imagesc(flipud(X))
colormap(map)

% Problem 6

imagesc(X)
colormap(1-gray)

% or 

colormap(flipud(gray)) 


% Problem 7
load clown
Y = X(:, [2:320,1]);
imagesc(abs(X-Y))
colormap(gray)

% cyclcally shift imagr to the left on unit. Vertical edge show up as white 


% Problem 8

load clown
Y = X(:, [2:320,1]);
Z = abs(X-Y);
M = max(Z(:))

M =

    75

eps = 0.5

eps =

    0.5000

Z(find(Z <eps*M)) = 0;

imagesc(Z)
colormap(gray)

% Problem 9

function E= energy(X)
  Y = X(:);
  E = Y'*Y/length(Y);

N = 2*rand(size(X))-1;


eps = 1; imagesc(X+eps*N); colormap(gray); energy(eps*N)/energy(X)

ans =

  2.5300e-004

eps = 5; imagesc(X+eps*N); colormap(gray); energy(eps*N)/energy(X)

ans =

    0.0063

eps = 10; imagesc(X+eps*N); colormap(gray); energy(eps*N)/energy(X)

ans =

    0.0253
    
% degradation begins to be noticble when eps = 5 and distortion is about 0.63 %