PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/falldetect/MHI.m

http://github.com/akshayp/Fall-Detect
Objective C | 51 lines | 39 code | 12 blank | 0 comment | 7 complexity | 5a9d3e5503799f16a106597c6263f768 MD5 | raw file
  1. %
  2. % ECE 4007 - Spring 2009
  3. %
  4. % MHI.m
  5. % Calculates the Motion History Image of the given video input
  6. % Author: Nicholas Chan
  7. % Date: February 16, 2009
  8. %
  9. % Assumptions: 15 FPS data; T = 15 frames (1 second) per fall
  10. function MHI = MHI(fg)
  11. % Initialize the output, MHI a.k.a. H(x,y,t,T)
  12. MHI = fg;
  13. % Define MHI parameter T
  14. T = 15; % # of frames being considered; maximal value of MHI.
  15. % Load the first frame
  16. frame1 = fg{1};
  17. % Get dimensions of the frames
  18. [y_max x_max] = size(frame1);
  19. % Compute H(x,y,1,T) (the first MHI)
  20. MHI{1} = fg{1} .* T;
  21. %Start global loop for each frame
  22. for frameIndex = 2:length(fg)
  23. %Load current frame from image cell
  24. frame = fg{frameIndex};
  25. %Begin looping through each point
  26. for y = 1:y_max
  27. for x = 1:x_max
  28. if (frame(y,x) == 255)
  29. MHI{frameIndex}(y,x) = T;
  30. else
  31. if (MHI{frameIndex-1}(y,x) > 1)
  32. MHI{frameIndex}(y,x) = MHI{frameIndex-1}(y,x) - 1;
  33. else
  34. MHI{frameIndex}(y,x) = 0;
  35. end
  36. end
  37. end
  38. end
  39. end