Colour channels and greyscale Open ↗
Code
% An RGB image is rows × columns × 3: one layer each for red, green and blue
I = testimage('shapes'); % built-in test image (uint8, 0–255)
size(I)
R = I(:, :, 1); G = I(:, :, 2); B = I(:, :, 3);
grey = rgb2gray(I);
subplot(2, 3, 1), imshow(I), title('RGB')
subplot(2, 3, 2), imshow(R), title('red')
subplot(2, 3, 3), imshow(G), title('green')
subplot(2, 3, 4), imshow(B), title('blue')
subplot(2, 3, 5), imshow(grey), title('rgb2gray')
subplot(2, 3, 6), imshow(255 - I), title('negative')