matlab利用imwrite()函数将图象另存为一幅bmp图像
时间: 2023-05-14 09:05:17 浏览: 136
可以使用以下代码将图像另存为bmp格式:
imwrite(img, 'filename.bmp', 'bmp');
其中,img是要保存的图像,'filename.bmp'是保存的文件名,'bmp'表示保存为bmp格式。
相关问题
5.利用imwrite()函数来压缩这幅图象,将其保存为一幅压缩了像素的jpg文件,设为flower.jpg;语法:imwrite(原图像,新图像,‘quality’,q), q取0-100。 6.同样利用imwrite()函数将最初读入的tif图象另存为一幅bmp图像,设为flower.bmp。 7.用imread()读入图像:Lenna.jpg 和camema.jpg; 8.用imfinfo()获取图像Lenna.jpg和camema.jpg 的大小; 9.用figure,imshow()分别将Lenna.jpg和camema.jpg显示出来,观察两幅图像的质量。 10.用im2bw将一幅灰度图像转化为二值图像,并且用imshow显示出来观察图像的特征。
5. 压缩图像并保存为jpg文件:
```matlab
img = imread('flower.tif');
imwrite(img, 'flower.jpg', 'quality', 50);
```
这里将原图像压缩为质量因子为50的jpg文件。
6. 将tif图像保存为bmp文件:
```matlab
img = imread('flower.tif');
imwrite(img, 'flower.bmp');
```
7. 读入图像Lenna.jpg和cameraman.jpg:
```matlab
img1 = imread('Lenna.jpg');
img2 = imread('cameraman.jpg');
```
8. 获取图像Lenna.jpg和cameraman.jpg的大小:
```matlab
info1 = imfinfo('Lenna.jpg');
info2 = imfinfo('cameraman.jpg');
size1 = info1.Width * info1.Height;
size2 = info2.Width * info2.Height;
```
这里使用imfinfo函数获取图像信息,然后计算出图像的大小。
9. 显示图像Lenna.jpg和cameraman.jpg:
```matlab
figure, imshow(img1);
figure, imshow(img2);
```
10. 将灰度图像转化为二值图像并且显示出来:
```matlab
gray_img = imread('gray_image.tif');
bw_img = im2bw(gray_img, 0.5);
imshow(bw_img);
```
这里将灰度图像转化为二值图像,阈值为0.5,然后显示出来观察图像的特征。
matlab AES图像加密
### MATLAB 实现 AES 图像加密
为了实现AES算法对图像进行加密,在MATLAB环境中可以调用内置函数`aesencrypt`和`aedesrypt`来完成这一操作。然而,由于这些并非MATLAB自带的标准库函数名称,实际应使用的是通过自定义函数或是借助第三方工具箱的方式来进行AES加解密工作[^2]。
下面给出一段利用MATLAB实现AES图像加密的简化示例代码:
```matlab
function encryptedImage = aesEncryptImage(imagePath, key)
% imagePath 是待加密图片路径;key 为用于AES加密的秘密钥
% 将输入图像读入内存并转换成适合处理的形式
originalImage = imread(imagePath);
% 对图像数据进行预处理,比如调整大小、灰度化等
processedImage = rgb2gray(originalImage);
% 把图像矩阵转化为向量形式以便后续处理
imageVector = double(reshape(processedImage,[],1));
% 使用指定长度的关键字初始化AES对象 (这里假设采用128位密钥)
cipher = matlab.aes.Cipher('Key',uint8(key), 'Mode','ECB');
% 执行加密运算
encryptedData = cipher.encrypt(uint8(imageVector));
% 将加密后的数据重新组织回原始尺寸的数组结构
[height,width] = size(processedImage);
encryptedMatrix = reshape(encryptedData,height*width,1);
% 输出最终得到的加密图像文件
imwrite(mat2gray(reshape(encryptedMatrix,[height width])), 'Encrypted.bmp');
end
```
此段程序展示了如何加载一张彩色或黑白图象作为输入,并对其进行简单的前处理之后再执行AES加密的过程。需要注意的是这里的`matlab.aes.Cipher()`并不是官方API的一部分,而是示意性质地表示创建了一个AES加密器实例。真正的应用开发中可能需要依赖外部库或者是MathWorks提供的特定产品特性支持。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)