1、实验内容

2、采样原理

3、实验程序

4．实验结果与分析

5．思考题

1、实验内容

2．实验原理

3、程序

4．实验结果与分析

5. 思考题

# 一、图像采样

## 3、实验程序

``````  %%程序一
b = rgb2gray(a);
[wid, hei] = size(b);
figure
imshow(b)
% 4倍减采样
quartimg = zeros(wid/2+1,hei/2+1);
i1 = 1;
j1 = 1;
for i = 1:2:wid
for j = 1:2:hei
quartimg(i1,j1) = b(i,j);
j1 = j1+1;
end
i1 = i1 +1;
j1 = 1;
end
figure
imshow(uint8(quartimg))

% 16倍减采样
quartimg = zeros(wid/4+1,hei/4+1);
i1 = 1;
j1 = 1;
for i = 1:4:wid
for j = 1:4:hei
quartimg(i1,j1) = b(i,j);
j1 = j1+1;
end
i1 = i1 +1;
j1 = 1;
end
figure
imshow(uint8(quartimg))``````

``````  %%程序二
b = rgb2gray(a);
[wid, hei] = size(b);
figure
imshow(b)

% 4倍减采样
b4 = b(1:2:end,1:2:end);
subplot(235);
imshow(b4);

% 16倍减采样
b16 = b(1:4:end,1:4:end);
subplot(236);
imshow(b16);``````

# 二、图像类型转换

## 3、程序

``````  a = imread('1.jpg');
b = rgb2gray(a);
[wid, hei] = size(b);
img256 = zeros(wid, hei);
img64 = zeros(wid, hei);
img32 = zeros(wid, hei);
img8 = zeros(wid, hei);
img2 = zeros(wid, hei);
for i=1:wid
for j=1:hei
img256(i,j)=floor(b(i,j)/1);
end
end
figure
subplot(151);
imshow(uint8(img256),[0,255])
for i=1:wid
for j=1:hei
img64(i,j)=floor(b(i,j)/4);
end
end
subplot(152);
imshow(uint8(img64),[0,63])
for i=1:wid
for j=1:hei
img32(i,j)=floor(b(i,j)/8);
end
end
subplot(153);
imshow(uint8(img32),[0,31])
for i=1:wid
for j=1:hei
img8(i,j)=floor(b(i,j)/32);
end
end
subplot(154);
imshow(uint8(img8),[0,7])
for i=1:wid
for j=1:hei
img2(i,j)=floor(b(i,j)/128);
end
end
subplot(155);
imshow(uint8(img2),[0,1])``````

## 5. 思考题

``````  %% 灰度转化