%  exercise 8 - solution

cd D:\courses\image\images

%image 1 
clear;
A=imread('lenna.jpg');     % reading the image
A=double(A);                  % working with double
[m n]=size(A);                % finding the matrix order
 for i=1:m                    % showing with uint8
     for j=1:n
        if   (i==1)  |  (j==1)  |   (i==m)  |  (j==n)  |  (i==m/2)  |  (j==n/2)  |  (i==j)  |  (i+j==m+1)
             A(i,j)=0;
         end
     end
 end
 A=uint8(A);
 figure,imshow(A)

% image 2
A=imread('lenna.jpg');
A=double(A);
[m n]=size(A);
 for i=2:5:m/2
     for j=2:5:n/2
         for k=i-1:i+1       % or by short  A(i-1:i+1,j-1:j+1)=255;
             for l=j-1:j+1
                 A(k,l)=255;
             end
         end
     end
 end
 A=uint8(A);
 figure,imshow(A)
 
% image 3
A=imread('lenna.jpg');
AA=double(A);
[m n]=size(AA);
B=30*ones(size(AA));
C=AA-B;
C=uint8(C);
imshow(A);
figure,imshow(C)

A=imread('lenna.jpg');
AA=double(A);
C=0.8*AA;
C=uint8(C);
imshow(A);
figure,imshow(C)

% image 4 
A=imread('lenna.jpg');
AA=double(A);
[m n]=size(AA);
B=30*ones(size(A));
C=AA+B;            
C=uint8(C);
imshow(A);
figure,imshow(C)

A=imread('lenna.jpg');
AA=double(A);
C=1.2*AA;
C=uint8(C);
imshow(A);
figure,imshow(C)

% image 5
A=imread('lenna.jpg');    
A=double(A);              
[m n]=size(A);            
for i=1:m                 
    for j=1:n
        B(i,j)=255;
    end
end
D = B - A;                
D=uint8(D);             
figure,imshow(D),

%image 6
A=imread('lenna.jpg');
A=double(A);
B=A';          % B = A transpose
B=uint8(B);
figure,imshow(B)

%image 7-9
A=imread('lenna.jpg');
A=double(A);
B=zeros(size(A));
[m n]=size(B);

for i=1:m
    for j=1:n
        if (i+j==1+n)
            B(i,j)=1;
        end
    end
end

figure, imshow(uint8(A*B)),
figure,imshow(uint8(B*A)),
figure,imshow(uint8(B*A*B))
