fork download
  1. a=imread('foreground.jpg');
  2. b=imread('background.jpg');
  3. da=double(a);
  4. db=double(b);
  5. D=imabsdiff(a,b);
  6. r=zeros(240,320);
  7. AR = da(:,:,1);
  8. AG = da(:,:,2);
  9. AB = da(:,:,3);
  10. BR = db(:,:,1);
  11. BG = db(:,:,2);
  12. BB = db(:,:,3);
  13.  
  14. mask = D(:,:,1)>20 & ...
  15. AR~=0 & AG~=0 & AB~=0 & ...
  16. BR./AR<4 & BR./AR>1.5 & ...
  17. BG./AG<2.8 & BG./AG>1.3 & ...
  18. BB./AB<2.05 & BB./AB>1.14 & ...
  19. BB./AB<BR./AR & BB./AB<BG./AG & BG./AG<BR./AR & ...
  20. abs(AR./(AR+AG+AB)-BR./(BR+BG+BB))<0.129 & ...
  21. abs(AG./(AR+AG+AB)-BG./(BR+BG+BB))<0.028 & ...
  22. abs(AB./(AR+AG+AB)-BB./(BR+BG+BB))<0.143;
  23. r(mask)=0;
  24. AR(mask) = 255;
  25. AG(mask) = 255;
  26. AB(mask) = 255;
  27.  
  28. h = cat(3,AR,AG,AB);
  29. imshow(h);
  30. im=h-a;
  31. imshow(im);
Success #stdin #stdout #stderr 0.21s 65040KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
error: imread: cannot find foreground.jpg
error: called from:
error:   /usr/share/octave/3.6.2/m/image/imread.m at line 53, column 5