figure(1);
pic=imread('23.jpeg');
subplot(221);
imshow(pic);
title('origin');
a=pic(end:-1:1,:,1:1:end);
subplot(223);
imshow(a);
title('right-left');
a=pic(:,end:-1:1,1:1:end);
subplot(224);
imshow(a);
title('down-up');
%figure1 is to show the picture of right-left and down-up.
%fugure2 is to show the result of the change of the third parameter.
figure(2);
a=pic(:,:,1:1:end);
%it could also be written as a=pic(:,:,1:3),beacuse there just 3 color aisle.
subplot(131);
imshow(a);
title('3par-positive sequence');
a=pic(:,:,end:-1:1);
subplot(132);
imshow(a);
title('3par-inverted sequence');
a=pic(:,:);
subplot(133);
imshow(a);
title('3par has been ignored');
虽然代码很长,但不要看了麻烦啦,其实要写一个翻转只有第一部分的代码啦。
其实还有一个疑惑,就是为什么有些图片第3个parameter如何改都是灰 {MOD}的呢,比如这张照片。明天课上问老师。
如果想要把图片保存到文件里,可以用imwrite;比如如下把right-left保存起来。
figure(1);
pic=imread('23.jpeg');
subplot(221);
imshow(pic);
title('origin');
a=pic(end:-1:1,:,1:1:end);
b=a;
subplot(223);
imshow(a);
title('right-left');
imwrite(a,'332.jpg');
这时翻转后的图片被命名为332存在了matlap的work文件夹里。