LAB 3 Đặng Đỗ Tuấn Kiệt

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

LAB 3: KĨ THUẬT SỐ HÓA TÍN HIỆU

Bài 1: Cho bức ảnh xám Test.bmp


- Thay đổi tần số lấy mẫu trên ảnh này.
- Quan sát ảnh, so sánh, đánh giá chất lượng và dung lượng ảnh, rút ra
nhận xét. Từ đó chọn ra tần số lấy mẫu tối ưu.
*Code:
gray_img = imread('D:\Test.bmp');
figure
gray_img_1 = imresize(gray_img, 1/2); %i=1
gray_img_2 = imresize(gray_img, 1/4); %i=2
gray_img_3 = imresize(gray_img, 1/8); %i=3
gray_img_4 = imresize(gray_img, 1/16); %i=4
gray_img_5 = imresize(gray_img, 1/32); %i=5
gray_img_6 = imresize(gray_img, 1/64); %i=6
gray_img_7 = imresize(gray_img, 1/128); %i=7

subplot(2,4,1);
imshow(gray_img);
title('2048x2048');

subplot(2,4,2);
imshow(gray_img_1);
title('1024x1024');

subplot(2,4,3);
imshow(gray_img_2);
title('512x512');

subplot(2,4,4);
imshow(gray_img_3);
title('256x256');

subplot(2,4,5);
imshow(gray_img_4);
title('128x128');

subplot(2,4,6);
imshow(gray_img_5);
title('64x64');

subplot(2,4,7);
imshow(gray_img_6);
title('32x32');

subplot(2,4,8);
imshow(gray_img_7);
title('16x16');

*Kết quả:
*Kết quả
Nhận xét: Khi thay đổi tần số lấy mẫu, có thể ảnh hưởng đến chất lượng và dung lượng ảnh.
Khi giảm tần số lấy mẫu thì chất lượng của ảnh sẽ giảm đi vì ta mất mát thông tin về ảnh gốc,
khiến ảnh đã lấy mẫu không còn đủ chi tiết và rõ nét như ảnh gốc. Khi ta giảm tần số lấy mẫu
thì dung lượng ảnh cũng giảm đi vì số lượng điểm ảnh trong ảnh sẽ giảm đi từ đó làm giảm
dung lượng ảnh.

- Chụp ảnh cả nhóm, chuyển về ảnh xám và thực hiện lại các yêu cầu trên.
*Code:
img = imread('D:\kiet.jpg');
gray_img = rgb2gray(img);
figure
gray_img_1 = imresize(gray_img, 1/2); %i=1
gray_img_2 = imresize(gray_img, 1/4); %i=2
gray_img_3 = imresize(gray_img, 1/8); %i=3
gray_img_4 = imresize(gray_img, 1/16); %i=4
gray_img_5 = imresize(gray_img, 1/32); %i=5
gray_img_6 = imresize(gray_img, 1/64); %i=6
gray_img_7 = imresize(gray_img, 1/128); %i=7

subplot(2,4,1);
imshow(gray_img);
title('2048x2048');

subplot(2,4,2);
imshow(gray_img_1);
title('1024x1024');

subplot(2,4,3);
imshow(gray_img_2);
title('512x512');

subplot(2,4,4);
imshow(gray_img_3);
title('256x256');

subplot(2,4,5);
imshow(gray_img_4);
title('128x128');

subplot(2,4,6);
imshow(gray_img_5);
title('64x64');

subplot(2,4,7);
imshow(gray_img_6);
title('32x32');

subplot(2,4,8);
imshow(gray_img_7);
title('16x16');

*Kết quả:

BÀI 2:
*Code:
img = imread('D:\Test.bmp');
%Vì mỗi pixel ảnh rgb được biểu diễn bằng n=8 bit (2^3=8), nên số màu
của ảnh là
%2^8 = 256 màu
figure
subplot(2,4,1);
d=2^(8-8); %(d=1)
q = round(img/d);
% Tính lại kích thước của ảnh sau khi lượng tử hóa (vì có làm tròn
kích thước mức lương tử hóa
Change_bit_img_1 = d*q;
imshow(Change_bit_img_1);
title('Anh goc 8 bit');

subplot(2,4,2);
d=2^(8-7); %d=2
q = round(img/d);
Change_bit_img_2 = d*q;
imshow(Change_bit_img_2);
title('Anh 7 bit');

subplot(2,4,3);
d=2^(8-6); %d=4
q = round(img/d);
Change_bit_img_3 = d*q;
imshow(Change_bit_img_3);
title('Anh 6 bit');

subplot(2,4,4);
d=2^(8-5); %d=8
q = round(img/d);
Change_bit_img_4 = d*q;
imshow(Change_bit_img_4);
title('Anh 5 bit');

subplot(2,4,5);
d=2^(8-4); %d=16
q = round(img/d);
Change_bit_img_5 = d*q;
imshow(Change_bit_img_5);
title('Anh 4 bit');

subplot(2,4,6);
d=2^(8-3); %d=32
q = round(img/d);
Change_bit_img_6 = d*q;
imshow(Change_bit_img_6);
title('Anh 3 bit');

subplot(2,4,7);
d=2^(8-2); %d=64
q = round(img/d);
Change_bit_img_7 = d*q;
imshow(Change_bit_img_7);
title('Anh 2 bit');

subplot(2,4,8);
d=2^(8-1); %d=128
q = round(img/d);
Change_bit_img_8 = d*q;
imshow(Change_bit_img_8);
title('Anh 1 bit');

*Kết quả:

*Nhận xét:
_ Nếu giảm số mức lượng tử hóa ảnh sẽ mất đi một phần thông tin và chi tiết,
cũng như chất lượng ảnh sẽ giảm xuống do số bit mã hóa mỗi pixel ảnh giảm đi
_ Chụp ảnh cả nhóm, chuyển về ảnh xám và thực hiện lại các yêu cầu trên.
*Code
img = imread('D:\kiet.jpg');
img = rgb2gray(img);

%Vì m?i pixel ?nh rgb ???c bi?u di?n b?ng n=8 bit (2^3=8), nên s? màu
c?a là
%2^8 = 256 màu
figure
subplot(2,4,1);
%S? m?c l??ng t? hóa cùa ?nh là 2^(n-k) v?i k là s? bit gi? l?i sai
%l??ng t? hóa
d=2^(8-8); %(d=1)
%l??ng t? hóa kích th??c c?a ?nh
q = round(img/d);
% Tính l?i kích?nh co th??c ?nh sau khi l??ng t? hóa (vì có làm tròn
kích th??c
% m?c l??ngh t? hóa
Change_bit_img_1 = d*q;
imshow(Change_bit_img_1);
title('Anh goc 8 bit');

subplot(2,4,2);
d=2^(8-7); %d=2
q = round(img/d);
Change_bit_img_2 = d*q;
imshow(Change_bit_img_2);
title('Anh 7 bit');

subplot(2,4,3);
d=2^(8-6); %d=4
q = round(img/d);
Change_bit_img_3 = d*q;
imshow(Change_bit_img_3);
title('Anh 6 bit');

subplot(2,4,4);
d=2^(8-5); %d=8
q = round(img/d);
Change_bit_img_4 = d*q;
imshow(Change_bit_img_4);
title('Anh 5 bit');

subplot(2,4,5);
d=2^(8-4); %d=16
q = round(img/d);
Change_bit_img_5 = d*q;
imshow(Change_bit_img_5);
title('Anh 4 bit');
subplot(2,4,6);
d=2^(8-3); %d=32
q = round(img/d);
Change_bit_img_6 = d*q;
imshow(Change_bit_img_6);
title('Anh 3 bit');

subplot(2,4,7);
d=2^(8-2); %d=64
q = round(img/d);
Change_bit_img_7 = d*q;
imshow(Change_bit_img_7);
title('Anh 2 bit');

subplot(2,4,8);
d=2^(8-1); %d=128
q = round(img/d);
Change_bit_img_8 = d*q;
imshow(Change_bit_img_8);
title('Anh 1 bit');

*Kết quả:

Bài 3:
*Code:
img = imread('D:\kiet.jpg');
figure
img1 = imresize(img,1/2); %i=1
img2 = imresize(img,1/4); %i=2
img3 = imresize(img,1/8); %i=3
img4 = imresize(img,1/16); %i=3
img5 = imresize(img,1/32); %i=5
img6 = imresize(img,1/64); %i=6
%img7 = imresize(img,1/128); %i=7
%img8 = imresize(img,1/256); %i=8

subplot(2,3,1);
imshow(img1);
title("1536x2048");

subplot(2,3,2);
imshow(img2);
title("768x1024");

subplot(2,3,3);
imshow(img3);
title("384x512");

subplot(2,3,4);
imshow(img4);
title("192x256");

subplot(2,3,5);
imshow(img5);
title("96x128");

subplot(2,3,6);
imshow(img6);
title("48x64");

*Nhận xét:
Khi tần số lấy mẫu giảm thì chất lượng ảnh sẽ giảm theo, vì mất mát thông tin nên
ảnh thu được sẽ không được chi tiết như ảnh gốc, cũng như giảm tần số lấy mẫu
sẽ làm giảm số lượng điểm ảnh trong ảnh nên chất lượng ảnh sẽ giảm
_ Thay đổi số mức lượng tử hoá trên ảnh này. Quan sát ảnh, so sánh,
đánh giá chất lượng ảnh và dung lượng ảnh, rút ra nhận xét.
*Code:
img = imread('D:\kiet.jpg');
figure

%anh 8 bit
subplot(2,4,1);
d=2^(8-8);
q=round(img/d);
change_bit_img_1 = d*q;
imshow(change_bit_img_1);
title('LTH Anh 8 bit');

subplot(2,4,2);
d=2^(8-7);
q=round(img/d);
change_bit_img_2 = d*q;
imshow(change_bit_img_2);
title('LTH Anh 7 bit');

subplot(2,4,3);
d=2^(8-6);
q=round(img/d);
change_bit_img_3 = d*q;
imshow(change_bit_img_3);
title('LTH Anh 6 bit');

subplot(2,4,4);
d=2^(8-5);
q=round(img/d);
change_bit_img_4 = d*q;
imshow(change_bit_img_4);
title('LTH Anh 5 bit');

subplot(2,4,5);
d=2^(8-4);
q=round(img/d);
change_bit_img_5 = d*q;
imshow(change_bit_img_5);
title('LTH Anh 4 bit');

subplot(2,4,6);
d=2^(8-3);
q=round(img/d);
change_bit_img_6 = d*q;
imshow(change_bit_img_6);
title('LTH Anh 3 bit');

subplot(2,4,7);
d=2^(8-2);
q=round(img/d);
change_bit_img_6 = d*q;
imshow(change_bit_img_6);
title('LTH Anh 2 bit');

subplot(2,4,7);
d=2^(8-2);
q=round(img/d);
change_bit_img_6 = d*q;
imshow(change_bit_img_6);
title('LTH Anh 2 bit');

subplot(2,4,8);
d=2^(8-2);
q=round(img/d);
change_bit_img_6 = d*q;
imshow(change_bit_img_6);
title('LTH Anh 1 bit');

*Kết quả:

*Nhận xét:
_ Số mức lượng tử hóa quyết định giá trị màu sắc được đại diện bởi số bit trong
ảnh số, nếu giảm số mức lượng tử hóa sẽ làm số bit bị nén nên màu sắc ảnh bị nén
theo => ảnh sẽ không chinh xác. Nếu tăng số mức lượng tử hóa thì số bit ảnh tăng
theo => lưu trữ được nhiều thông tin về màu sắc hơn => ảnh cho ra sẽ sắc nét hơn

You might also like