Define a function Subsamp, enter a color image file name, output and display the color of half the size
Image (original, flip horizontally, flip vertically, center area red). You must use the control statement to successfully invoke the command Window!
Because color images are 3-dimensional, black-and-white images are 2-dimensional. If we're still using it when we halve the size of the image
>> f=imread (' e:\1.png ');>> f=f (1:2:end,1:2:end);>> imshow (f);
We'll find out. Three gray images arranged in a single side
So you can add 1 dimensions to the back.
The entire code is as follows
function [Img1,img2,img3,img4]=subsamp (filename); img1=imread (filename); i=1:4 Figure switch I case 1 img1=img1 (1:2:end,1:2:end,:);% makes the image size halved imshow (IMG1); Case 2 img2=img1 (end:-1:1,:,:);% causes the image to flip horizontally imshow (IMG2); Case 3 img3=img1 (:, end:-1:1,:);% causes the image to flip vertically imshow (IMG3); Case 4 100*100 the image Center area red [M,n,t]=size (IMG1); IMG4=IMG1; IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,1) =255; IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,2) =0; IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,3) =0; Imshow (IMG4); EndEnd
Run results
Color image reading and writing experiment of MATLAB operation