Position Extraction and Tracking in Matlab - matlab

I am not a good programmer, and I am new to Matlab. I have recorded video of myself juggling 3 balls of different colors (Red, White, and Yellow). I used uncompressed .avi files at 30fps, and have around 460Gb of data. My plan is to use ~1 minute of video (1800 frames) from each recording and make a 2D position (y-axis) vs. time (x-axis) graph. Each ball would be on the graph drawn in its own color. I have downloaded this script
(http://www.mathworks.com/matlabcentral/fileexchange/28512-simplecolordetectionbyhue--)
but I am not sure if this is a good place to start or not. Any suggestions? I can play the videos just fine using implay, but VideoReader seems to have a problem since the file is quite large.

Related

Fast movie creation using MATLAB and ffmpeg

I have some time series data that I would like to create into movies. The data could be 2D (about 500x10000) or 3D (500x500x10000). For 2D data, the movie frames are simply line plot using plot, and for 3D data, we can use surf, imagesc, contour etc. Then we create a video file using these frames in MATLAB, then compress the video file using ffmpeg.
To do it fast, one would try not to render all the images to display, nor save the data to disk then read it back again during the process. Usually, one would use getframe or VideoWriter to create movie in MATLAB, but they seem to easily get tricky if one tries not to display the figures to screen. Some even suggest plotting in hidden figures, then saving them as images to disk as .png files, then compress them using ffmpeg (e.g. with x265 encoder into .mp4). However, saving the output of imagesc in my iMac took 3.5s the first time, then 0.5s after. I also find it not fast enough to save so many files to disk only to ask ffmpeg to read them again. One could hardcopy the data as this suggests, but I am not sure whether it works regardless of the plotting method (e.g. plot, surf etc.), and how one would transfer data over to ffmpeg with minimal disk access.
This is similiar to this, but immovie is too slow. This post 3 is similar, but advocates writing images to disk then reading them (slow IO).
maybe what you're trying to do is to convert your data into an image by doing the same kind of operation that surf, or imagesc or contour is doing and then writing it to a file directly, that would keep all the data in the memory until writing is needed.
I had little experience with real images that could also work here:
I saw that calling imshow took lot of time, but changing the CData of a presetted figure created by the imshow function took around 5ms, so, maybe you could set a figure using any of the function you like, and then update the underlying XData, YData etc. so that the figure will update in the same fashion?
best of luck!

Record screen in real time using MATLAB?

I am using an optical microscope and camera to record some videos which are post-processed in MATLAB.
Real time acquisition and pixel statistics would be extremely helpful, because some of what I am looking at absorbs very little light (I am using transmission mode). An example is that a blank (background) sample would give me an an average pixel value across a 512x512 ccd array of something like 144 (grayscale). An actual sample might have an average value of 140 or so. This subtle shift in pixel intensity would be useful in helping me focus the microscope.
Unfortunately, my camera setup is not supported by MATLAB, so I cannot use the image acquisition toolbox for real time. So I was wondering, is there a way that I could 'fake' real time image acquisition by selecting say a rectangle of my current desktop (the rectangle that is the video output of the microscopes camera), for matlab to record in real time?
Thanks

Matlab: accessing both image sequences from a 3D video file

I have recorded a 3D video using a Fujifilm Finepix Real 3d w3 camera. The resulting video file is a single AVI, so the frames from both lenses must somehow be incorporated within the single file.
I now wish to read in the video into Matlab such that I have two image sequences, each corresponding to either the left lens or the right lens.
So far I have played back the AVI file using the computer vision toolbox functions (vision.VideoFileReader etc), however it ignores one of the lenses and plays back only a single lens' image sequence.
How do I access both image sequences within Matlab?

how to generation animation as mpg or speed up gif in matlab

I am plotting a randomly walking points on the figure and trying to capture the motion at each step by getframe. After I collect all the frames, I output the result as avi with movie2avi, but the output file was so big to fit into my presentation. I am looking for a way to export the movie to mp4, anyone have any idea? I also try to use the 3rd party movie2gif, it save the size to huge extent but when I play the gif, it looks so unsmooth
In later versions of Matlab (e.g. 2012) it is done by creating and writing a video object. For example, the following code generates movie of a randomly moving circle. You can adjust the speed of the movie with the FrameRate and the size with the Quality properties. For more details see the Matlab documentation.
vobj=VideoWriter('MyMovieFile', 'Motion JPEG AVI');
vobj.FrameRate=4;
vobj.Quality=75
open(vobj);
for i=1:100
plot(rand,rand,'o')
F=getframe(gcf);
writeVideo(vobj, F);
cla(gca)
end
close(vobj)

How to generate and play white noise on the fly with OpenAL?

I'm using OpenAL in my app to play sounds based on *.caf audio files.
There's a tutorial which describes how to generate white noise in OpenAL:
amplitude - rand(2*amplitude)
But they're creating a buffer with 1000 samples and then just loop that buffer with
alSourcei(source, AL_LOOPING, AL_TRUE);
The problem with this approach: Looping white noise just doesn't work like this because of DC offset. There will be a noticeable wobble in the sound. I know because I tried looping dozens of white noise regions generated in different applications and all of them had the same problem. Even after trying to crossfade and making sure the regions are cut to zero crossings.
Since (from my understanding) OpenAL is more low-level than Audio Units or Audio Queues, there must be a way to generate white noise on the fly in a continuous manner such that no looping is required.
Maybe someone can point out some helpful resources on that topic.
The solution with the least change might just be to create a much longer OpenAL noise buffer (several seconds) such that the wobble is at too low rate to easily hear. Any waveform hidden in a 44Hz repeat (1000 samples at 44.1k sample rate) is within normal human hearing range.