1.编写 M 文件。
用过 Matlab 的人应该都接触过 M 文件,在 Matlab 中编辑 M 文件的方法就是在命令窗口输入 >> edit filename ,我看的第一本 Matlab 的书没有教这个,特别说一下。
>> edit imgReadShowSave
下面代码中的图片我放在工作目录下的 Bitmap 文件夹下。
2.对图像的读写,显示和保存的基本操作
%% 图像的读写,显示保存
% 作者:杨宇东
% 日期:2014.09.22
% 参数:无
% 输出:无
%%
function imgReadShowSave
% 源图片文件名
imgFile = 'Bitmap/1.bmp';
% 新的普通 JPG 格式文件名
newNormalJPGFile = 'Bitmap/newNormalJPGFile.jpg';
% 新的高品质 JPG 格式文件名
newHighQualityJPGFile = 'Bitmap/newHighQualityJPGFile.jpg';
% 新的低品质 JPG 格式文件名
newLowQualityJPGFile = 'Bitmap/newLowQualityJPGFile.jpg';
% 新的 PNG 格式文件名
newPNGFile = 'Bitmap/newPNGFile.png';
fprintf('读取 BMP 图像中...\n');
% 通过 imread 函数将图片文件读入到 img 数组中, img 为三维数组, 分别为纵坐标像素、横坐标像素、 RBG 颜色
img = imread(imgFile