title: Matlab - Scale down an image using an average of four pixels
body: <p>I have just started learning image-processing and Matlab and I'm trying to scale down an image using an average of 4 pixels. That means that for every 4 original pixels I calculate the average and produce 1 output pixel. 
  So far I have the following code:</p>
  
  <pre><code>img = imread('bird.jpg');
  row_size = size(img, 1);
  col_size = size(img, 2);
  res = zeros(floor(row_size/2), floor(col_size/2));
  figure, imshow(img);
  for i = 1:2:row_size
      for j = 1:2:col_size
          num = mean([img(i, j), img(i, j+1), img(i+1, j), img(i+1, j+1)]);
          res(round(i/2), round(j/2)) = num;
      end
  end
  figure, imshow(uint8(res));
  </code></pre>
  
  <p>This code manages to scale down the image but it converts it to grayscale. 
  I understand that I probably have to calculate the average of the <strong>RGB</strong> components for the output pixel but I don't know how to access them, calculate the average and insert them to the result matrix. </p>