计算机视觉KNN图像分类源码下载

%-----------西安电子科技大学计算机视觉大作业之KNN应用------%

%-----------本实验需要准备15张图片,并全部剪裁成200x200---%

%------------------作者:郭斌全-----------------------%

%-----欢迎关注【科研果园】微信公众号,这是作者本人的公众号----%

%-------------打开微信搜索"outputing"-----------------%

%4+1 cat data

white_cat=imread('whitecat_200x200.png');

black_cat=imread('blackcat_200x200.png');

stand_cat=imread('standcat_200x200.jpg');

sit_cat=imread('sitcat_200x200.jpg');

cut_cat=imread('cutcat_200x200.jpg');

white_cat=rgb2gray(white_cat);

black_cat=rgb2gray(black_cat);

stand_cat=rgb2gray(stand_cat);

sit_cat=rgb2gray(sit_cat);

cut_cat=rgb2gray(cut_cat);

white_cat=double(white_cat);

black_cat=double(black_cat);

stand_cat=double(stand_cat);

sit_cat=double(sit_cat);

cat_new=double(cut_cat);

white_cat=pca(white_cat);

black_cat=pca(black_cat);

stand_cat=pca(stand_cat);

sit_cat=pca(sit_cat);

cat_new=pca(cat_new);

%4+1 human data

%human=imread('human_200x200.png');

human_killer=imread('human_killer_200x200.jpg');

human_big=imread('human_big_200x200.jpg');

human_king=imread('human_king_200x200.jpg');

human_officer=imread('human_officer_200x200.jpg');

human_mk=imread('human_mk_200x200.jpg');

%human=rgb2gray(human);

human_killer=rgb2gray(human_killer);

human_big=rgb2gray(human_big);

human_king=rgb2gray(human_king);

human_officer=rgb2gray(human_officer);

human_mk=rgb2gray(human_mk);

%human=double(human);

human_killer=double(human_killer);

human_big=double(human_big);

human_king=double(human_king);

human_officer=double(human_officer);

human_mk=double(human_mk);

human_killer=pca(human_killer);

human_big=pca(human_big);

human_king=pca(human_king);

human_officer=pca(human_officer);

human_mk=pca(human_mk);

%4+1 dog data

dog_1=imread('dog_1_200x200.jpg');

dog_2=imread('dog_2_200x200.jpg');

dog_3=imread('dog_3_200x200.jpg');

dog_4=imread('dog_4_200x200.jpg');

dog_new=imread('dog_new_200x200.jpg');

dog_1=rgb2gray(dog_1);

dog_2=rgb2gray(dog_2);

dog_3=rgb2gray(dog_3);

dog_4=rgb2gray(dog_4);

dog_new=rgb2gray(dog_new);

dog_1=double(dog_1);

dog_2=double(dog_2);

dog_3=double(dog_3);

dog_4=double(dog_4);

dog_new=double(dog_new);

dog_1=pca(dog_1);

dog_2=pca(dog_2);

dog_3=pca(dog_3);

dog_4=pca(dog_4);

dog_new=pca(dog_new);

%human_mk test

human_new_human_1_dist=dist_m(human_mk,human_killer);

human_new_human_2_dist=dist_m(human_mk,human_king);

human_new_human_3_dist=dist_m(human_mk,human_big);

human_new_human_4_dist=dist_m(human_mk,human_officer);

human_new_cat_1_dist=dist_m(human_mk,white_cat);

human_new_cat_2_dist=dist_m(human_mk,black_cat);

human_new_cat_3_dist=dist_m(human_mk,stand_cat);

human_new_cat_4_dist=dist_m(human_mk,sit_cat);

human_new_dog_1_dist=dist_m(human_mk,dog_1);

human_new_dog_2_dist=dist_m(human_mk,dog_2);

human_new_dog_3_dist=dist_m(human_mk,dog_3);

human_new_dog_4_dist=dist_m(human_mk,dog_4);

%human_mk_dog_new_dist=dist_m(human_mk,dog_new);

%dog_test

dog_new_human_1_dist=dist_m(dog_new,human_killer);

dog_new_human_2_dist=dist_m(dog_new,human_king);

dog_new_human_3_dist=dist_m(dog_new,human_big);

dog_new_human_4_dist=dist_m(dog_new,human_officer);

dog_new_cat_1_dist=dist_m(dog_new,white_cat);

dog_new_cat_2_dist=dist_m(dog_new,black_cat);

dog_new_cat_3_dist=dist_m(dog_new,stand_cat);

dog_new_cat_4_dist=dist_m(dog_new,sit_cat);

dog_new_dog_1_dist=dist_m(dog_new,dog_1);

dog_new_dog_2_dist=dist_m(dog_new,dog_2);

dog_new_dog_3_dist=dist_m(dog_new,dog_3);

dog_new_dog_4_dist=dist_m(dog_new,dog_4);

%cat test

cat_new_human_1_dist=dist_m(cat_new,human_killer);

cat_new_human_2_dist=dist_m(cat_new,human_king);

cat_new_human_3_dist=dist_m(cat_new,human_big);

cat_new_human_4_dist=dist_m(cat_new,human_officer);

cat_new_cat_1_dist=dist_m(cat_new,white_cat);

cat_new_cat_2_dist=dist_m(cat_new,black_cat);

cat_new_cat_3_dist=dist_m(cat_new,stand_cat);

cat_new_cat_4_dist=dist_m(cat_new,sit_cat);

cat_new_dog_1_dist=dist_m(cat_new,dog_1);

cat_new_dog_2_dist=dist_m(cat_new,dog_2);

cat_new_dog_3_dist=dist_m(cat_new,dog_3);

cat_new_dog_4_dist=dist_m(cat_new,dog_4);

human_new_human_1_dist

human_new_human_2_dist

human_new_human_3_dist

human_new_human_4_dist

human_new_cat_1_dist

human_new_cat_2_dist

human_new_cat_3_dist

human_new_cat_4_dist

human_new_dog_1_dist

human_new_dog_2_dist

human_new_dog_3_dist

human_new_dog_4_dist

dog_new_human_1_dist

dog_new_human_2_dist

dog_new_human_3_dist

dog_new_human_4_dist

dog_new_cat_1_dist

dog_new_cat_2_dist

dog_new_cat_3_dist

dog_new_cat_4_dist

dog_new_dog_1_dist

dog_new_dog_2_dist

dog_new_dog_3_dist

dog_new_dog_4_dist

cat_new_human_1_dist

cat_new_human_2_dist

cat_new_human_3_dist

cat_new_human_4_dist

cat_new_cat_1_dist

cat_new_cat_2_dist

cat_new_cat_3_dist

cat_new_cat_4_dist

cat_new_dog_1_dist

cat_new_dog_2_dist

cat_new_dog_3_dist

cat_new_dog_4_dist

function dist_all=dist_m(a,b)

%dist=double(a)-double(b);

dist=a-b;

dist_abs=abs(dist).*abs(dist);

%dist=human-white_cat;

x=size(dist);

dist_all =double(0);

for i=1:x

dist_all = dist_all+dist_abs(i);

end

end

你可能感兴趣的:(计算机视觉KNN图像分类源码下载)