You are on page 1of 12

BO CO

BI TP LN A PHNG TIN


Sinh vin : Phm Tuyt Nhung
MSSV : 20109571
Lp : CN-TVT3 - K55
GVHD : TS. Vng Hong Nam














1

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


b. Hin th 3 nh R,G,B .
Code:
2

X =imread('Meobeo.jpg');
figure(1)
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(ptn,3);
image(mean);
Kt qu:
6



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

7

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(ptn)*70/100;
image(giam);
8
g. Tng cng trung bnh ca nh 50% .
tang =image(ptn)*150/100;
image(tang);
2. Nhp 1 nh xm v bin i sang nh m bn.
Code :
ptn=imread ('phamtuyetnhung.jpg');
image(ptn);
gray =rgb2gray(ptn);
for i =1:256;
for j =1:256;
amban (i,j) =255 - gray(i,j);
end
end
image(amban);
kt qu :
9
Histogram ca nh gray v m bn ln lt l
10
PHN B:
Code:
rbg=imread(phamtuyetnhung.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
11
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:






12

You might also like