cemif.m
上传用户:sundar2007
上传日期:2020-06-25
资源大小:48k
文件大小:2k
源码类别:

matlab例程

开发平台:

Matlab

  1. function [fusion] = cemif(im1,im2,op,r,consistency)
  2. %
  3. %cemif.m, v 1.1 2002/02/06 18:01:40
  4. %===========================================================================
  5. %               Eduardo Fernandez Canga - University of Bath
  6. %
  7. %                        Copyright (c) 2001
  8. %===========================================================================
  9. %
  10. %                [fusion] = cemif(im1,im2,op,r,consistency)
  11. %
  12. %               im1: input image
  13. %               im2: input image
  14. %                op: selection of background fussion method
  15. %                     1 - first image background  (default)
  16. %                     2 - second image background
  17. %                     3 - both backgrounds 
  18. %                 r: averaging mask size (default 11)
  19. %       consistency: apply consistency
  20. %                       1=yes (default)
  21. %                       0=no 
  22. %
  23. %===========================================================================
  24. if nargin < 5, consistency=1;end
  25. if nargin < 4, r=11;end
  26. if nargin < 3, op=1;end
  27. if any (size(im1)~=size(im2))
  28.     error('Error: Different Size Images')
  29. end
  30. %Calculating backgrounds
  31. back1=imaver(im1,r);
  32. back2=imaver(im2,r);
  33. %Calculating foregrounds
  34. fore1=im1-back1;
  35. fore2=im2-back2;
  36. %Fusion of foregrounds
  37. decision=abs(fore1)>abs(fore2);
  38. if consistency==1               % apply consistency check if it is active
  39.     mask=ones(3,3)/9;           % use 3x3 window mask
  40.     decision=impad(double(decision),1);
  41.     decision=round(conv2(decision,mask,'valid'));
  42. end
  43. fore=fore1.*decision+fore2.*(~decision);
  44. %Fusion of backgrounds
  45. switch op
  46. case 1 % Selected backgrounds of img 1
  47.     back=back1;
  48. case 2 % Selected backgrounds of img 2
  49.     back=back2;
  50. case 3 % Selected both backgrounds
  51.     m1=mean(mean(im1));
  52.     m2=mean(mean(im2));
  53.     back=back1+back2-(m1+m2)/2;
  54. otherwise
  55.     error('Invalid input for background fussion method');
  56. end
  57. fusion=back+fore;