Download presentation
Presentation is loading. Please wait.
1
EP375 Computational Physics
Topic 14 VIDEO PROCESSING Department of Engineering Physics University of Gaziantep Apr 2016
2
Content Example Applications Functions to be used: VideoReader()
rgb2gray() im2bw() imshow() regionprops()
3
Introduction We have seen 2D or 3D plots of basic data.
In this chapter we will discus some of the elementary processes that can be applied to images.
4
% vp0.m % frames to movie % get 1.bmp, 2.bmp and 3.bmp from course web page % clear; clc; count = 0; Nframe = 3; Dframe = 5; mov = avifile('example.avi','compression','None'); for i=1:Nframe name = strcat(num2str(i),'.bmp'); v = imread(name); while count<Dframe count = count + 1; imshow(v); F = getframe(gca); mov = addframe(mov, F); end count = 0; mov = close(mov);
5
% vp1.m % reading video info clc; clear v = VideoReader('laser.avi'); t = v.Duration fr = v.FrameRate nFrame = uint32(t * fr) v1 = read(v,30); % get 30th frame imshow(v1) % diplay
6
% vp2.m % reading video info clc; clear v = VideoReader(‘freefall.avi'); t = v.Duration fr = v.FrameRate nFrame = uint32(t * fr) for i=1:nFrame v1 = read(v,i); % get ith frame imshow(v1) % diplay end
8
% vp3.m % reading video clc; clear %v = VideoReader('laser.avi'); v = VideoReader(‘fallingball3.avi'); t = v.Duration; fr = v.FrameRate; nFrame = uint32(t * fr); for i=1:nFrame A = read(v, i); % get ith frame B = rgb2gray(A); % convert to gray scale C = B>175; % convert to black-white subplot(2,2,1); imshow(A) subplot(2,2,2); imshow(B); subplot(2,2,3); imshow(C) pause(1/fr); end
9
% vp4.m % ccd clc; clear v = VideoReader('laser.avi'); t = v.Duration; fr = v.FrameRate; nFrame = uint32(t * fr); v1 = rgb2gray(read(v,1)); % get 1st frame v3 = rgb2gray(read(v,1)); % get 1st frame for i=2:nFrame v2 = rgb2gray(read(v,i)); v3 = v3 + imabsdiff(v1,v2); imshow(v3) end
10
% vp5.m % circles a = imread('circles.png'); g = rgb2gray(a); bw = g > 100; imshow(bw) stats = regionprops('table',bw,'Centroid',... 'MajorAxisLength','MinorAxisLength') centers = stats.Centroid; diameters = mean([stats.MajorAxisLength ... stats.MinorAxisLength],2); radii = diameters/2; hold on viscircles(centers,radii); hold off
11
% vp6.m % tracker clear; clc; v = VideoReader('laser.mp4'); t = v.Duration; fr = v.FrameRate; nFrame = uint16(t * fr); newvid = VideoWriter('newfile'); newvid.FrameRate=8; open(newvid) for k = 50:200 v1 = read(v,k); imshow(v1) v2 = im2bw(v1,0.8); stat = regionprops(v2); [w, h] = size(stat); if size(stat) > 0 rectangle('Position', stat(1).BoundingBox, 'EdgeColor', 'b'); cX = stat(1).Centroid(1); cY = stat(1).Centroid(2); fprintf('%d %d\n',cX,cY); end frame = getframe; writeVideo(newvid,frame); close(newvid)
12
% vp7.m % measurement of gravitational acceleration from video clear; clc; v = VideoReader('fallingball7.avi'); nFrame = uint16(v.Duuration * v.FrameRate); v1 = read(v,1); % get first frame for k = 2:nFrame v2 = read(v,k); v3 = imabsdiff(v1,v2); v4 = im2bw(v3,0.2); imshow(v4); stat = regionprops(v4); if size(stat) > 0 rectangle('Position', stat(1).BoundingBox,'EdgeColor', 'g'); cX = stat(1).Centroid(1); cY = stat(1).Centroid(2); fprintf('%d -> %d %d\n',k,cX,cY); T(k) = double(k)/fr; y(k) = cY; end frame = getframe; % size of ping ball is 42mm which corresponds 15px in the video t = T(2:end); y = (v.Height-y(2:end)) * 42e-3/15; plot(t,y,'*')
13
References: [1]. Numerical Methods for Engineers, 6th Ed. S.C. Chapra, Mc Graw Hill (2010) [2]. [3]. Numerical Methods in Engineering with MATLAB, J. Kiusalaas, Cambridge University Press (2005) [4]. Essential MATLAB for Engineers and Scientist, 3rd Ed Hahn B., Valentine D.T. (2007) [5]. Computational Physics, Giordano J.N. Prentice Hall (1997)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.