You are on page 1of 7

ti 6 : Vit chng trnh x l nh tnh tin trong my bn hng t ng

Nhm 1 : Trn ng Khoa Trn Minh Khu Trn ng Hng Mch Y Vinh Mai Th Anh

Gii Thut :
Bc 1 : Chuyn hnh nh cc ng xu trong nh RGB sang nh cc mc xm (nh nh phn)

Bc 2 : Ta s tch ng bin ca nh, l cc im nh c chi thay i t ngt. Do hnh nh kh d sng nn khi tch ra ta vn dc cc m en trong ng xu.

Bc 3: Nhim v ca ta by gi l tch lc b hon ton cc m en bn trong ng xu v dng hm strel cc ng xu l 1 hnh trn nguyn vn.

Bc 4 : tch c hnh trn trong hnh trn, ta phi nh s th t cc vng nh ln cn nhau bng hm Label v lu gi tng hnh trn trong 1 ma trn.
Sau y l hnh nh tch ra ca tng ng xu :

Bc 6 : xc nh ng xu no c gi tr tng ng vi 100,200,1000,2000,5000 ta phi xc nh bn knh ca tng hnh trn. Ta s dng bin i Euclidean, sau gi tr ln nht ca mng cha bin i trn chnh l bn knh ca hnh trn. Da vo bn knh ta s bit dc gi tr, sau xut ra mn hnh.

Code chng trnh x l nh v cho bit gi tr ca ng xu


close all; clear all; clc; fprintf('Bai tap Xu ly am thanh hinh anh \n Nhom 1 : \n Tran Dang Khoa \n Mach Y Vinh \n Tran Dang Hung \n Tran Minh Khue\n Mai The Anh \n') fprintf('\n De bai : Nhan dien gia tri cac dong xu tu hinh anh bang Matlab \n') % Huong dan su dung : Nhap ten duong dan file vao Matlab hoac dung hinh anh % co san theo vi du sau % vd : | Xin moi nhap vao ten file anh(dinh dang *.jpeg) :tien_x.jpg| file = input('\n Xin moi nhap vao ten file anh(dinh dang *.jpeg) :','s'); %Xuat ra man hinh chuoi ki tu va dua du lieu vao I = imread(file);% Nhap hinh anh de xu ly I=rgb2gray(I);% Chuyen hinh anh RGB thanh anh xam figure;imshow(I);%Hien thi anh sau khi chuyen sang cac muc xam c = edge(I, 'canny',0.3); % Tach bien cua anh, voi nguong la 0.3 figure; imshow(c); se = strel('disk',2); I2 = imdilate(c,se); imshow(I2); %Tao cau truc ma tran loc hinh tron %Gian no anh theo cau truc cua ham strel vua tao ra

d2 = imfill(I2, 'holes'); % To vung trong moi dong tien figure, imshow(d2); Label=bwlabel(d2,4); %Gan nhan cho cac thanh phan co trong anh %Tao ma tran kich thuoc tuong ung voi moi dong xu a1=(Label==1); a2=(Label==2);

a3=(Label==3); a4=(Label==4); a5=(Label==5); T=[5000 1000 200 500 2000]; string='Hinh %d co gia tri %d VND \n'; notstring='Day khong phai la dong xu co gia tri VND \n'; disp('Theo thu tu cac hinh hien thi o Figure, cac dong xu co gia tri la : ') for n = 4:8 if (n==4) m=a1; elseif (n==5) m=a2; elseif (n==6) m=a3; elseif (n==7) m=a4; else m=a5; end k= bwdist(~m); % Tinh khoang cach Euclidean toi pixel khac 0 gan nhat figure, imshow(k,[]), % Hien thi anh D1 voi cac muc xam, theo nguong min max cua ma tran dua vao rad=max(max(k)); % Gia tri lon nhat cua array chinh la ban kinh duong dong xu % Ham xac dinh dong xu theo ban kinh if (rad>95)&(rad<96) fprintf(string,n,T(1)) elseif (65<rad) & (rad<66) fprintf(string,n,T(2)) elseif (75<rad) & (rad<76) fprintf(string,n,T(3)) elseif (82<rad) & (rad<83) fprintf(string,n,T(4)) elseif (86<rad) & (rad<88) fprintf(string,n,T(5)) else fprintf(notstring) end end

Cc hm dng trong chng trnh :


close : xa 1 ca s xc nh close all : xa ton b ca s ang thc thi hoc n clear: xa khng gian lm vic clear all: xa ton b hm , gi tr , m flie khi khng gian lm vic clc : xa ca s lnh fprintf : ghi d liu vo file text fprintf(A \n,B \n ... ) : xut A,B ra thnh tng dng trn mn hnh input : yu cu nhp d liu vo v tr v d liu dc nhp user_entry = input('prompt', 's') : gi tr a vo l mt chui k t ch ko phi tn bin hoc gi tr s imread: c cc file nh [...] = imread(filename) : c file nh c tn filename rgb2gray: chuyn i nh mu RGB thnh nh xm edge: tch bin ca nh [g , t ] = edge(f, canny, T, sigma): Trong T l mt vect, l 2 ngng c gii thch trong bc 3 ca th tc trc v sigma l lch chun ca b lc lm trn. Nu t gp vo thng s ng ra, n l vect 2 phn t cha 2 gi tr ngng c dng bi thut ton. C php n gin c gii thch nh cc phng php khc, bao gm vic t ng tnh ton T nu n khng c cung cp. Gi tr mc nh ca sigma l 1 figure : to 1 ca s mi imshow : hin th nh imshow(c ): hin th nh xm