project2.asv
上传用户:miaohui010
上传日期:2013-01-08
资源大小:2540k
文件大小:2k
开发平台:

Matlab

  1. load human;
  2. load background;
  3. for j=1:10
  4. k_s=1;
  5. k_d=120;
  6. hm_tr(250,252)=0;
  7. hm_test(250,252)=0;
  8. [hm_tr,hm_test]=randQ(human);
  9. randQ(background);
  10. bg_tr(250,252)=0;
  11. bg_test(250,252)=0;
  12. [bg_tr,bg_test]=randQ(background);
  13. M_hm=hm_tr(1,k_s:k_d);
  14. for i=2:250
  15. M_hm=M_hm+(hm_tr(i,k_s:k_d));
  16. end
  17. M_hm=M_hm/250;
  18. M_bg=bg_tr(1,k_s:k_d);
  19. for i=2:250
  20. M_bg=M_bg+(bg_tr(i,k_s:k_d));
  21. end
  22. M_bg=M_bg/250;
  23. E_hm(k_d-k_s+1,k_d-k_s+1)=0;
  24. E_bg(k_d-k_s+1,k_d-k_s+1)=0;
  25. for i=1:250
  26.     E_hm=E_hm+(hm_tr(i,k_s:k_d)-M_hm)'*(hm_tr(i,k_s:k_d)-M_hm);
  27.     E_bg=E_bg+(bg_tr(i,k_s:k_d)-M_bg)'*(bg_tr(i,k_s:k_d)-M_bg);
  28. end
  29. E_hm=E_hm/250;
  30. E_bg=E_bg/250;
  31. %test________________________________________________________
  32. flag_hm(250)=0;
  33. flag_bg(250)=0;
  34. for i=1:250
  35.     dk_hm=log(0.5)+log(0.95)-log(abs(det(E_bg)))/2-((hm_test(i,k_s:k_d)-M_bg)*inv(E_bg)*(hm_test(i,k_s:k_d)-M_bg)')/2;
  36.     dk_bg=log(1.5)+log(0.05)-log(abs(det(E_hm)))/2-((hm_test(i,k_s:k_d)-M_hm)*inv(E_hm)*(hm_test(i,k_s:k_d)-M_hm)')/2;
  37.     if(dk_hm<=dk_bg)
  38.         flag_hm(i)=1;
  39.     else flag_hm(i)=0;
  40.     end
  41. end
  42. s2_hm=sum(flag_hm);
  43. for i=1:250
  44.     dk_hm=log(0.5)+log(0.95)-log(abs(det(E_bg)))/2-((bg_test(i,k_s:k_d)-M_bg)*inv(E_bg)*(bg_test(i,k_s:k_d)-M_bg)')/2;
  45.     dk_bg=log(1.5)+log(0.05)-log(abs(det(E_hm)))/2-((bg_test(i,k_s:k_d)-M_hm)*inv(E_hm)*(bg_test(i,k_s:k_d)-M_hm)')/2;
  46.     if(dk_hm>=dk_bg)
  47.         flag_bg(i)=1;
  48.     else flag_bg(i)=0;
  49.     end
  50. end
  51. s2_bg=sum(flag_bg);
  52. err_hg(j)=(250-s2_hm)/500;
  53. err_gh(j)=(250-s2_bg)/500;
  54. end
  55. ERR_HG=0;
  56. ERR_GH=0;
  57. for j=1:10
  58.     ERR_HG=ERR_HG+err_hg(j);
  59.     ERR_GH=ERR_GH+err_gh(j);
  60. end
  61. ERR_HG=ERR_HG/10;
  62. ERR_GH=ERR_GH/10;
  63.