You are on page 1of 11

BO CO

BI TP LN A PHNG TIN


Sinh vin : Phm Th Tho
MSSV : 20109564
Lp : CN-TVT3 - K55
GVHD : TS. Vng Hong Nam














1

Phn A:
Bi 1:
1. Np d liu file nh mu phamthithao.jpg vo mng ma trn Matlab.
a. Hin th file nh mu ny:
Code:
ptt=imread('phamthithao.jpg');
image(ptt);
Kt qu:


b. Hin th 3 nh R,G,B .
Code:
X =imread('Meobeo.jpg');
figure(1)
2

image(X);
R =X(:,:,1);
image(R), colormap([[0:1/255:1]', zeros(256,1), zeros(256,1)]), colorbar;
Kt qu:


%Green Component
G =X(:,:,2);
figure;
image(G), colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]), colorbar;
Kt qu:
3


%Blue component
B =X(:,:,3);
figure;
image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), colorbar;
Kt Qu
4




c. V histogram ca 3 nh ny.
Code:
imhist(R)
imhist(G)
imhist(B)
Kt qu:

5



d. Tnh ton cng trung bnh ca nh.
Code: mean =mean(ptt,3);
image(mean);
Kt qu:

e. Hin th nh sau khi s dng hm rbg2gray
Code: gray =rbg2gray(ptt);
image(gray);

Chiu ca bc nh sau khi thc hin hm rgb2gray l 2 chiu , trong khi , bc
nh u c 3 chiu. iu ny c th gii thch bi bc nh u tin c chiu th
3 lu tr d liu v 3 mu R,G,B ca n, khc vi bc nh gray(khng c 3
thnh phn R,G,B).
f. Gim cng trung bnh ca anh 30%
Code :
giam =image(ptt)*70/100;
image(giam);
6



7


g. Tng cng trung bnh ca nh 50% .
tang =image(ptt)*150/100;
image(tang);

2. Nhp 1 nh xm v bin i sang nh m bn.
Code :
ptt=imread ('phamthithao.jpg');
image(ptt);
gray =rgb2gray(ptt);
for i =1:256;
for j =1:256;
amban (i,j) =255 - gray(i,j);
end
end
image(amban);
8

kt qu :


Histogram ca nh gray v m bn ln lt l


9



PHN B:
Code:
rbg=imread(phamthithao.jpg);
gray=rgb2gray(c);
[rows columns] =size(gray);

% hien thi buc anh dau tien.
subplot(2, 2, 1);
imshow(gray, []);
title('Original Gray Scale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% cong nhieu Gauusian vao buc anh
noisyImage =imnoise(gray, 'gaussian', 0, 0.003);

% hien thi buc anh thu hai.
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Noisy Image');
squaredErrorImage =(double(gray) - double(noisyImage)) .^2;
% hien thi anh ve loi binh phuong .
subplot(2, 2, 3);
imshow(squaredErrorImage, []);
title('Squared Error Image');
% tong loi binh Phuong chia cho (m.n)
% de tinh gia tri Mean Squared Error.
mse =sum(sum(squaredErrorImage)) / (rows * columns);
% tinh toan PSNR (Peak Signal to Noise Ratio) tu MSE
10

PSNR =10 * log10( 256^2 / mse);
% ket qua
message =sprintf('The mean square error is %.2f.\nThe PSNR =%.2f', mse,
PSNR);
msgbox(message);

Kt qu:






11

You might also like