... NhậnDạngKhuônMặt*Matlab2013cóhàmhỗtrợnhậndạngkhuônmặt.tacóthểsửdụnghàmhỗtrợnàynhưsau:functionbai10()%Example1:Facedetection%faceDetector=vision.CascadeObjectDetector();%Default:findsfacesOrigin=imread('path_image\.jpg');bboxes=step(faceDetector,Origin);%Detectfaces%AnnotatedetectedfacesIFaces=insertObjectAnnotation(Origin,'rectangle',bboxes,'Face');figure,imshow(IFaces),title('Detectedfaces');end*Ýtưởngthựchiệnviếtchươngtrình(khôngsửdụnghàmhỗtrợ):Sơđồkhốicho bài toánTạo1cơsởdữliệugồmnảnh,mỗiảnhđượcđặttêntheothứtựlàcácsónguyêntừ1đếnnđểtiệnchoviệcquản lý tập ảnhnày(ntùyvàosốlượngảnh).Ảnhđượcđưavào tập cơsởdữliệusẽđượcdùngđểhuấnluyện,từđâysửdụngcácphươngpháptríchrútđặctrưngvàđưaravectođặctrưngchoviệcnhậndạng.Khiđưaảnhcầnnhậndạngvàotathựchiệntínhtọađộhìnhchiếucủaảnhnàyvàcủacảnhữngảnhtrongcơsởdữliệuđãcó,rồiđemsosánhkếtquả.Thựchiệnđokhoảngcách(khoảngcáchEuclid)giữatọađộhìnhchiếucủaảnhcầnkiểmtravớitọađộhìnhchiếucủacácảnhtrongcơsởdữliệu.Bứcảnhnàotrongcơsởdữliệucókhoảngcáchsovớiảnhcầnkiểmtralàngắnnhấtthìtachọn.kenhR=origin(:,:,1);subplot(3,2,3),imshow(kenhR),title('Red');kenhG=origin(:,:,2);subplot(3,2,4),imshow(kenhG),title('Green');kenhB=origin(:,:,3);subplot(3,2,5),imshow(kenhB),title('Blue');trungviR=medfilt2(kenhR,[33]);trungviG=medfilt2(kenhG,[33]);trungviB=medfilt2(kenhB,[33]);rgb_filtered=cat(3,trungviR,trungviG,trungviB);gray_filtered=medfilt2(gray,[33]);gray_RGB=rgb2gray(rgb_filtered);d=abs(gray_RGBgray_filtered);subplot(3,2,6),imshow(d,[]),title('saikhac');endViếtchươngtrìnhMatlabthựchiệnnhậndạngmộtđốitượngtùyý(1chữcái,chữsố, vật thểbấtkỳ,…)BÀITẬPXỬLÝẢNHSỐ1) ... NhậnDạngKhuônMặt*Matlab2013cóhàmhỗtrợnhậndạngkhuônmặt.tacóthểsửdụnghàmhỗtrợnàynhưsau:functionbai10()%Example1:Facedetection%faceDetector=vision.CascadeObjectDetector();%Default:findsfacesOrigin=imread('path_image\.jpg');bboxes=step(faceDetector,Origin);%Detectfaces%AnnotatedetectedfacesIFaces=insertObjectAnnotation(Origin,'rectangle',bboxes,'Face');figure,imshow(IFaces),title('Detectedfaces');end*Ýtưởngthựchiệnviếtchươngtrình(khôngsửdụnghàmhỗtrợ):Sơđồkhốicho bài toánTạo1cơsởdữliệugồmnảnh,mỗiảnhđượcđặttêntheothứtựlàcácsónguyêntừ1đếnnđểtiệnchoviệcquản lý tập ảnhnày(ntùyvàosốlượngảnh).Ảnhđượcđưavào tập cơsởdữliệusẽđượcdùngđểhuấnluyện,từđâysửdụngcácphươngpháptríchrútđặctrưngvàđưaravectođặctrưngchoviệcnhậndạng.Khiđưaảnhcầnnhậndạngvàotathựchiệntínhtọađộhìnhchiếucủaảnhnàyvàcủacảnhữngảnhtrongcơsởdữliệuđãcó,rồiđemsosánhkếtquả.Thựchiệnđokhoảngcách(khoảngcáchEuclid)giữatọađộhìnhchiếucủaảnhcầnkiểmtravớitọađộhìnhchiếucủacácảnhtrongcơsởdữliệu.Bứcảnhnàotrongcơsởdữliệucókhoảngcáchsovớiảnhcầnkiểmtralàngắnnhấtthìtachọn.kenhR=origin(:,:,1);subplot(3,2,3),imshow(kenhR),title('Red');kenhG=origin(:,:,2);subplot(3,2,4),imshow(kenhG),title('Green');kenhB=origin(:,:,3);subplot(3,2,5),imshow(kenhB),title('Blue');trungviR=medfilt2(kenhR,[33]);trungviG=medfilt2(kenhG,[33]);trungviB=medfilt2(kenhB,[33]);rgb_filtered=cat(3,trungviR,trungviG,trungviB);gray_filtered=medfilt2(gray,[33]);gray_RGB=rgb2gray(rgb_filtered);d=abs(gray_RGBgray_filtered);subplot(3,2,6),imshow(d,[]),title('saikhac');endViếtchươngtrìnhMatlabthựchiệnnhậndạngmộtđốitượngtùyý(1chữcái,chữsố, vật thểbấtkỳ,…)BÀITẬPXỬLÝẢNHSỐ1) Lọcảnh(sửdụngphéptươngquan)trênmiềnkhônggianfiltered=spatial_filter(image,mask)Trongđóimagelàảnhxámcầnlọc,masklàmặtnạlọc(kíchthướcmỗichiềulàsốlẻ),filteredlàảnhsaukhilọc. Bài làm:functionloc_anh=spatial_filter(image,mask)clc;closeall;[row_image,colum_image]=size(image);[row_mask,colum_mask]=size(mask);fori=1:row_image+2*floor(row_mask/2)forj=1:colum_image+2*floor(colum_mask/2)loc_anh(i,j)=0;endendfori=1:row_imageforj=1:colum_imageloc_anh(i+floor(row_mask/2),j+floor(colum_mask/2))=image(i,j);endendfori=1:row_imageforj=1:colum_imagebientam=0;foru=1:row_maskforv=1:colum_maskbientam=bientam+loc_anh(ifloor(row_mask/2)+u,jfloor(colum_mask/2)+v)*mask(u,v);endendimage(i,j)=bientam;endendloc_anh=image;endThaotác:(tacómatrậnAlàảnhvàmlàmặtnạlọctùyý)>> ... Thựchiệnlọctrungvị,lọcmin,lọcmax,lọcmidpointchomộtảnhxámvớimặtnạlọccókíchthướcnnbấtkỳ(nlẻvàn>1). Bài làm:chọnn=3function[locmax,locmin,trungvi,midpoint]=locminmax(image,n)clc;closeall;[row_image,colum_image]=size(image);fori=1:row_image+2*floor(n/2)forj=1:colum_image+2*floor(n/2)loc_anh(i,j)=0;endendfori=1:row_imageforj=1:colum_imageloc_anh(i+floor(n/2),j+floor(n/2))=image(i,j);endendforI=1:row_imageforj=1:colum_imagemax=loc_anh(ifloor(n/2)+1,jfloor(n/2)+1);min=loc_anh(ifloor(n/2)+1,jfloor(n/2)+1);foru=1:nforv=1:ntrung_vi(u,v)=loc_anh(ifloor(n/2)+u,jfloor(n/2)+v);ifloc_anh(ifloor(n/2)+u,jfloor(n/2)+v)>maxmax=loc_anh(ifloor(n/2)+u,jfloor(n/2)+v);endifloc_anh(ifloor(n/2)+u,jfloor(n/2)+v)<minmin=loc_anh(ifloor(n/2)+u,jfloor(n/2)+v);endendend Bài làm:...