akoangsimula
Member level 5
- Joined
- Aug 3, 2010
- Messages
- 84
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,288
- Location
- Batangas - Malvar
- Activity points
- 1,763
Hi,
You have to detect motion in some video or how? kindly elaborate your problem.
akoangsimula said:SUPER thank you..
it helps me a lot..
i will do it step by step.
by the way if i have question can i ask you?
this is our final thesis by the way
GodBless
Hi,
Yes you can ask anything you want to but here in this thread and i would be more than happy to help you.
/SC
please help me asap .. its my project and i did not get itHi,
ok here you go:
1- First of all you have to make sure that Video is read by Matlab. I do not know in which format you will make video with your camera. But I have done it with 'avi' format. In matlab command of 'aviread' will be used to read the video. you can search matlab help to find commands for other video formats. Lets for example you have saved your videofile(avi format) with name of 'filename' on your computer. Then how you will load it in matlab for further processing,here are some commands which will help you(you can see their details with matlab help)
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 checkisplay 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.
/SC
i did not get that from where the idiff(i,j) .. from where come the i,j if only the difference value of inew-iold store in idiff only?The proper procedure required to accomplish the task was sufficiently explained above.
+++
The proper procedure required to accomplish the task was sufficiently explained above.
+++
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?