clear all;
close all
clc;
image_height = 400;
image_width = 400;
for i = 1 : image_height
for j = 1 : image_width
red(i,j) = uint8(mod(j-1,256));
green(i,j) = uint8(mod(j-1,256));
blue(i,j) = uint8(mod(j-1,256));
end
end
rgb = zeros(image_height,image_width,3,'uint8');
rgb(:,:,1) = red;
figure
imshow(rgb);
rgb(:,:,2) = green;
figure
imshow(rgb);
rgb(:,:,3) = blue;
figure
imshow(rgb);
imshow(rgb);
imwrite(rgb,'my_pic.bmp')
执行效果