圖像數字化_採樣和量化樣例。

一、前言:

這部分是數字圖像處理與分析中第一章第六小節的圖像數字化的內容,爲方便理解圖像數字化這個概念。
圖像數字化=採樣+量化。

二、內容回顧

數字化目的:

主要用於模擬圖像。由於圖像處理的對象是數字圖像,模擬圖像需要數字化才能得到數字圖像。
圖像數字化的操作過程主要分爲:採樣量化
採樣: 把空間上的連續圖像分割成離散的像素的集合。
量化: 把像素的灰度(濃淡)變換成離散的整數值的操作。

特點:

1.採樣越細(採樣間隔越小),像素越小,圖像越精細。
2.量化越細緻(比特數越大),灰度分辨率越高,灰度(濃淡層次)表現越豐富。

採樣樣例:

%採樣是把空間上的連續的圖像分割成離散的像素的集合。

img =  imread('boy.bmp');
img1 = rgb2gray(img);
img2 = img1(1:2:end,1:2:end);%縮小1/4
img3 = img1(1:4:end,1:4:end);%縮小1/8
img4 = img1(1:8:end,1:8:end);%縮小1/16
img5 = img1(1:16:end,1:16:end);%縮小1/32
imshow(img),title('原圖');
figure,imshow(img1),title('256*256');%打開新窗口,RGB轉爲灰度圖像
figure,imshow(img2),title('128*128');
figure,imshow(img3),title('64*64');
figure,imshow(img4),title('32*32');
figure,imshow(img5),title('16*16');

%圖形窗口劃分2*3顯示區域
figure,
subplot(2,3,1),imshow(img),title('原圖');
subplot(2,3,2),imshow(img1),title('256*256');%RGB轉爲灰度圖像
subplot(2,3,3),imshow(img2),title('128*128');
subplot(2,3,4),imshow(img3),title('64*64');
subplot(2,3,5),imshow(img4),title('32*32');
subplot(2,3,6),imshow(img5),title('16*16'); %會出現棋盤效應

在這裏插入圖片描述
在這裏插入圖片描述

量化樣例:

%量化(quantization)是把像素的灰度(濃淡)變換成離散的整數值的操作。量化越細緻(比特數越大),即灰度分辨率越高,灰度級數(濃淡層次)表現越豐富。
img =  imread('boy.bmp');
img1 = rgb2gray(img);%RGB轉爲灰度圖像
img1 = double(img1);%img1轉化成double數值類型
img2 = round(img1/4)*4;%縮小1/4,再求整
img3 = round(img1/16)*16;%縮小1/16,再求整
img4 = round(img1/32)*32;%縮小1/32,再求整
img5 = round(img1/64)*64;%縮小1/64,再求整
img6 = (img1>=128)*128;%將原圖像中灰度值大於等於128時爲128,其餘爲0
figure,imshow(img),title('原圖');

%圖形窗口劃分2*3顯示區域
figure,
subplot(2,3,1),imshow(uint8(img1)),title('8比特(256級)');
subplot(2,3,2),imshow(uint8(img2)),title('6比特(64級)');
subplot(2,3,3),imshow(uint8(img3)),title('4比特(16級)');
subplot(2,3,4),imshow(uint8(img4)),title('3比特(8級)');
subplot(2,3,5),imshow(uint8(img5)),title('2比特(4級)');
subplot(2,3,6),imshow(uint8(img6)),title('1比特(2級)');

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章