hello guys!!..
can anyone teach me how motion detection done in matlab??
thanks..
or is there anyone who can give his or her code for that,,
Thank You..
Motion Detection in Matlab

video=aviread(’filename.avi’): read avi video into Matlab;
movie(video): play the movie with the file name ’video’
length(video): total number of frames in the video:
I=frame2im(video(j)): extract the jth frame from video to image I
size(I): determine the size of I, i.e., number of rows, columns, color or gray image
rgb2gray: convert an rgb image to a gray-scale image.
imwrite(I,filename,’bmp’): e.g. filename=’frame5’, then image named as ’frame5.bmp’ will be saved to the harddisk.
What you have achieved uptill now,you have loaded your 'Video'in matlab,played it via matlab. Then you have divided the whole video into frames and extracted each frame into image and saved it. Now you are ready to do further processing on these images to check the presence on motion.
2- Now load 2 consecutive images that you have saved in Step 1. Assigned the 2 images as 'Iold' and 'Inew' names, respectively.
Compute the difference between the 2 consecutive image frames (Idiff = Inew - Iold). Apply a fixed threshold to the difference image (i.e. Initially set a threshold value, e.g. th=50/255(or you can set any other threshold according to your needs)for image value ranges [0,1]). Set zeros to those pixels whose values are below the threshold (i.e. if |Idiff(i, j)| < threshold, then Idiff(i, j) = 0.0).
Divide the image area into rectangular blocks (size 16×16 or any size you want).Within each block indexed as (j, i), if there is one 'Idiff' value within the block containing the motion, then the block is assigned as a motion block, otherwise, it is a non motion block. Repeat this process over all blocks. Generate a
map image (same size as the original image) for indicating motion blocks and name it as ”Imotion”:for those pixels within the motion blocks, assign image values as 1.0, otherwise 0.0.
To search the whole image you can use the follwoing syntaxthe pixels within the block, having the block indexes (j,i), are
[(j - 1) * blocksize + 1 : j * blocksize, (i - 1) * blocksize + 1 : i * blocksize].
Check sum(sum(Idiff[ (j-1)*blocksize+1:j*blocksize, (i-1)*blocksize+1: i*blocksize]) for the motion inside the block.
Matlab functions useful to read image fiels are,
imread: read an image from a file
mat2gray: convert an image, from the pixel value range: [Imin,Imax] to a matrix image with a range [0.0 1.0].(Note: converting between image formats is very important for Matlab image processing.)When usng mat2gray, the image pixels extracted from video are usually 8 bits unsigned char (range between 0-255), while most Matlab processing requires pixels in float/double format. There are many other functions for image format conversion, e.g. ind2gray, gray2ind, rgb2gray. You can use Matlab’s help to find out more.
Now to check:Display 3 images: the 2 (original) consecutive images, and the motion image ”Imotion”. Observe the motion blocks, and change the threshold value th until the motion blocks indeed include all prominent changes in the image frames.
Plot ”Imotion” obtained in above step and observe whether or not the motion blocks cover most motion areas in the original image: if not, then change the threshold th value until ”Imotion” shows satisfactory motion areas. Its an hit an trial method. you have to do it untill u r satisifed with results.
So you have detected any motion in your Video using Matlab through Image subtraction(block based) technique.
Hope it help you.
Source:
[url=http://www.theengineeringprojects.com/2016/07/motion-detection-matlab.html]MOTION DETECTION IN MATLABi will use a camera to human and then detect the human in the scene,,
by image subtraction..
how it process in matlab?