数字图像处理_实验2_图像采样与量化

计算机与信息工程学院实验报告

实验题目:实验2-图像采样与量化

实验目的:理解图像采样与量化的原理,掌握图像采样与量化的实现方法。

实验环境(硬件和软件):PC机、 Matlab软件                         

实验内容:

(1)对图像分别采样为256×256、128×128、64×64的图像。

(2)对图像分别量化为64级灰度图像、32级灰度图像和8级灰度图像。

参考代码:

示例一

% 读取图片
img = imread('填入图片路径'); 

% 创建采样的figure
figure;

% 原图
subplot(2,2,1);
imshow(img);
title('学号-姓名'); 
xlabel('(a) 原图');

% 采样为256x256
subplot(2,2,2);
img_256 = imresize(img, [256 256]);
imshow(img_256);
title('学号-姓名'); 
xlabel('(b) 256×256');

% 采样为128x128
subplot(2,2,3);
img_128 = imresize(img, [128 128]);
imshow(img_128);
title('学号-姓名'); 
xlabel('(c) 128×128');

% 采样为64x64
subplot(2,2,4);
img_64 = imresize(img, [64 64]);
imshow(img_64);
title('学号-姓名'); 
xlabel('(d) 64×64');

% 保存采样结果的figure为图片
saveas(gcf, 'sampled_images.png');

% 创建量化的figure
figure;

% 原图
subplot(2,2,1);
imshow(img);
title('学号-姓名'); 
xlabel('(a) 原图');

% 量化为64级灰度
subplot(2,2,2);
img_64_gray = grayslice(mat2gray(img), 64);
imshow(img_64_gray,[]);
title('学号-姓名');
xlabel('(b) 64级灰度');

% 量化为32级灰度
subplot(2,2,3);
img_32_gray = grayslice(mat2gray(img), 32);
imshow(img_32_gray,[]);
title('学号-姓名'); 
xlabel('(c) 32级灰度');

% 量化为8级灰度
subplot(2,2,4);
img_8_gray = grayslice(mat2gray(img), 8);
imshow(img_8_gray,[]);
title('学号-姓名');
xlabel('(d) 8级灰度');

% 保存量化结果的figure为图片
saveas(gcf, 'quantized_images.png');

%From:TengMMVP

示例二

addpath("请添加图片所在路径");
photo = imread("请添加图片名称"); % 读取文件

% 对图像进行不同程度采样
p256 = photo(1:2:end, 1:2:end, :);
p128 = photo(1:4:end, 1:4:end, :);
p64 = photo(1:8:end, 1:8:end, :);

% 显示图片
figure;
subplot(2,2,1);
imshow(photo);
title('学号-姓名');
xlabel("(a) 原图");

subplot(2,2,2);
imshow(p256);
title('学号-姓名'); 
xlabel("(b) 256×256");

subplot(2,2,3);
imshow(p128);
title('学号-姓名');
xlabel("(c) 128×128");

subplot(2,2,4);
imshow(p64);
title('学号-姓名'); 
xlabel("(d) 64×64");

% 对图像进行不同程度量化
p64 = histeq(photo, 64);
p32 = histeq(photo, 32);
p8 = histeq(photo, 8);

% 显示图片
figure;
subplot(2,2,1);
imshow(photo);
title('学号-姓名'); 
xlabel("(a) 原图");

subplot(2,2,2);
imshow(p64);
title('学号-姓名');
xlabel("(b) 64级灰度");

subplot(2,2,3);
imshow(p32);
title('学号-姓名'); 
xlabel("(c) 32级灰度");

subplot(2,2,4);
imshow(p8);
title('学号-姓名'); 
xlabel("(d) 8级灰度");

%From:TengMMVP
  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值