实验项目2 图像采样与量化

实验内容

1)对图像分别采样为256x256128x12864x64的图像。将原图和经采样后的图像放在同一个figure

2)对图像分别量化为64级灰度图像、32级灰度图像和8级灰度图像。将原图和经采样后的图像放在同一个figure

% 读取原始图像
originalImage = imread('face.jpg'); 

% 创建一个新的figure
figure;

% 绘制原始图像
subplot(2, 2, 1);
imshow(originalImage);
xlabel('原图');

% 采样为256x256的图像
sampledImage256 = imresize(originalImage, [256, 256]);
subplot(2, 2, 2);
imshow(sampledImage256);
xlabel('256x256');

% 采样为128x128的图像
sampledImage128 = imresize(originalImage, [128, 128]);
subplot(2, 2, 3);
imshow(sampledImage128);
xlabel('128x128');

% 采样为64x64的图像
sampledImage64 = imresize(originalImage, [64, 64]);
subplot(2, 2, 4);
imshow(sampledImage64);
xlabel('64x64');

% 1. 读取原始图像
originalImage = imread('face.jpg'); 

% 2. 分别对灰度图像进行不同级别的量化
quantizedImage64 = uint8(double(originalImage) / 256 * 64); % 64级灰度
quantizedImage32 = uint8(double(originalImage) / 256 * 32); % 32级灰度
quantizedImage8 = uint8(double(originalImage) / 256 * 8);   % 8级灰度
quantizedImage8_ = uint8(floor(double(originalImage) / 256 * 8));
% 3. 将原始图像和经量化后的图像放在同一个figure中显示
figure;

subplot(2, 2, 1);
imshow(originalImage);
xlabel('原始图像');

subplot(2, 2, 2);
imshow(quantizedImage64, []);
xlabel('64级灰度');

subplot(2, 2, 3);
imshow(quantizedImage32, []);
xlabel('32级灰度');

subplot(2, 2, 4);
imshow(quantizedImage8, []);
xlabel('8级灰度');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值