% load and cut
img=imread('helmet.jpg');
img=im2double(img(1:512, 1:496,:));
imshow(img);


% GRAY
figure
img1 = sum(img,3) / 3;
imshow(img1);


% quantize to n colors
n=4;
img2=floor(img1*n)/n;
figure
imshow(img2)


% subsample
figure
n=8
Y=1:n:512;
X=1:n:496;

imgsub=im2double(img(Y,X));
sizex=length(imgsub(1,:));
sizey=length(imgsub(:,1));
newpic=[];
for r=1:sizey
    row=[];
    for c=1:sizex
        pixmatrix=zeros(n)+imgsub(r,c);
        row=[row pixmatrix];
    end
    newpic=[newpic; row];
end
imshow(newpic);

    
        
