实验内容
(1)对图像分别采样为256x256、128x128、64x64的图像。将原图和经采样后的图像放在同一个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级灰度');