Message Boards Message Boards

Complex behavior and patterns in tracking of street pedestrian movement

Posted 12 years ago
I have a project for find a rate of people movement using a video recording. That was one of the projects that i have to submit aside my PhD research.

> The Main Objective that i had been asked to present is to visualise the data of a complex behaviour that happens in a spesific streets of (cars-busses-pedisterian).

And I tackled this point by extracting the data from a recorded video and not by mimicing the behaviour through simulations

> I didn't focus on counting the people (even it is possiple as i tried it and still need to be developed) but aiming to return movment patterns on where the people stands/pass more in the street which can be applied in the future for redesigning the place elements (shades - seats ...etc).

> and there is some impediments in this technique till now such as : if the movie had been recorded in a sunny day, the shadows will be taken into account
  • If the people who wear gray, they are the same as street.
  • As much height/angle of the camera as much accurate patterns .... etc.
Anyway, mainly i make a differenceimage function between a frame without people in the street, and "others many frames may be 200 to 1000", So i would like to find a way to make my code faster) how to compile this kind of Mathematica functions of "image processing" _for example
 frame1 = 10050; frame2 = 10118;
 
 f = Colorize[
    ColorNegate[
     ArrayPlot[
      Mean[Table[
            h = Import[ "C:\\MVI_5002.mov", {"ImageList", 10000}];   
            hh = Import[ "C:\\MVI_5002.mov", {"ImageList", t}];
            hhh = ImageDifference[h, hh];
           Morphh = MorphologicalBinarize[hhh, {0.1, .8}];
           ImageData[Morphh],
         {t, frame1, frame2}]],
      ImageSize -> 1000]],
   ColorFunction -> "Rainbow"];

Export["C:\\render\\" <> ToString[r1] <> "-" <>     ToString[r3] <> ".tif", f];


================ UPDATE ==================== 

Here is the result after this discussion and my further efforts:

POSTED BY: Mohamed Zaghloul
6 Replies
Functions such as MorphologicalBinarize and ColorNegate are usually already compiled.
Compile does not have much to work with in your example.
POSTED BY: Bruce Miller
I agree with Bruce, you have just a few image processing functions and they are already compiled. But there are other ways to optimize code.

- Use ParallelTable instead of Table if you have multiple CPUs.

- Why is this line inside Table if it does not depend on variable t? You could run it once outside Table, instead of many times inside Table. Importing is resource draining.
h = Import[ "C:\\MVI_5002.mov", {"ImageList", 10000}];

- Why are you importing again in Table for the file you already imported? This line
hh = Import[ "C:\\MVI_5002.mov", {"ImageList", t}];

could be just this:
hh = h[[1;;t]]
POSTED BY: Vitaliy Kaurov
Yes vitaliy, you are right, i should made the import only once and call it. and Moreover i tried CUDA (colornegate&ImageSubtract) it works well even theres is a little difference in results between image difference and image subtract but it's not bad at least because i subtract a similar images and a small changes between them. 
POSTED BY: Mohamed Zaghloul
Hi, here is the output, you can watch video here: Pedestrian Movement - Mathematica

POSTED BY: Mohamed Zaghloul
This is quite spectacular, Mohamed! We added a snapshot to your post. Is it all done by that little code you posted originally or there is more to this? It feels like only motion is affected, - so are you taking ImageDifference anywhere in your actual code? Could you also let us know a few more details about it - for example how idea came around what are you ultimately trying to do?
POSTED BY: Vitaliy Kaurov
The Image Processing algorithm is to analyze movement of People who are going out from a bus .
That was done by analyzing the differences of pixels color values between a picture of the streets which are empty from people and frames of the movies which show the movement of people. Then clusterize and get the mean value which applied to gradient colors that discribe the hieghst and lowest changes of the movement.

Still under development

Recipe:

A) import >>>Run this Once
k= frame without people (croped the upper part)
k2= movie frames folder
kk= movie frames with people movment (croped the upper part)

k = ImageCrop[Import["C:\\t3\\10050.png"], {Full, 285}, Top];
SetDirectory["C:\\t3"]; names = FileNames[]; k2 = Import /@ names;
kk = Table[ImageCrop[k2[], {Full, 285}, Top], {t, 2, Length[k2]}];

----------------------------------------------------------------------------------------------------------------
   
  differences [from    to  ]
return >>>
b- run the next once for all the movie frames example [ 1 to 1000]
C) Run the next again for a different ranges  for example [ 200 to 400 - 401 to 600 - 601 to 800 - 801 to 1000]
 endframe = 1000;
 firstframe = 1;
 e = Colorize[
    ColorNegate[
     ArrayPlot[
      Mean[Table[
        ImageData[
         MorphologicalBinarize[
          ImageDifference[k, kk[[i]]], {0.05, .45}]], {i, firstframe ,
        endframe}]], ImageSize -> 1017]], ColorFunction -> "Rainbow"];
Export["C:\\heatmaprender\\" <> ToString[2] <> "-" <>
   ToString[endframe] <> ".png", e];

--------------------------------------------------------------------------------------------------
D) ColorReplace for purple color to be transperent in all of the output images
--------------------------------------------------------------------------------------------------
E) Combine the frames with original movie which was colored (here i converted it to grayscale) _ only in this step you can use Mathematica or any video editing software then save avi/mov ....etc

POSTED BY: Mohamed Zaghloul
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract