Code covered by the BSD License  

Highlights from
Vibration from frames

image thumbnail

Vibration from frames

by

 

this can be used to extract the frequency of a simple harmonic vibrations from frames

Frequency=vibration_from_images(FPS,base_name_of_frame,nb_of_frames,start_from_frame)
function Frequency=vibration_from_images(FPS,base_name_of_frame,nb_of_frames,start_from_frame)
% vibration_from_images is a function that can be used to compute the
% frequency of simple harmonic vertical vibrations captured by a series of
% images(or a video that has been comverted to images(see video2pic.m in
% matlab central).The mass in the image has a black horizontal landmark that
% facilitiates the detection of the mass throught the use of hough transform(Hough_Grd.m).
% Check Read_Me.m for more information.
% Inputs: 
%         FPS: frames per seconds from the original movie
%         base_name_of_frame: the base name of the image excluding the frame number
%         nb_of_frames: total number of frames to be processed
%         start_from_frame: the first frame to start the image processing
%         from. 
% Outputs:
%         Frequency: frequency of the vibration measured in rad/sec
%Example usage: Frequency=vibration_from_images(20,'Video.avi_',200,80)
% Written by Nassim Khaled, Ph.D. 2012
% Acknowledgments: Tao Peng for sharing Hough_Grd.m  
%                  Shiquan Wang for saring video2pic.m
 


%browse and select an image
[filename, pathname, filterindex]=uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' },'mytitle')
% read the image
I_color = imread(strcat(pathname,filename));
%display image
imshow(I_color)


[x,y]=ginput(2);
x=[min(x) max(x)];
y=[min(y) max(y)];
Y=[];
Time=[];
j=0;
for i=start_from_frame:nb_of_frames
    if i<10
        name=strcat(strcat(strcat(strcat(base_name_of_frame,'000'),num2str(i)),'.jpg'));
    elseif i<100
        name=strcat(strcat(strcat(strcat(base_name_of_frame,'00'),num2str(i)),'.jpg'));
    else
        name=strcat(strcat(strcat(strcat(base_name_of_frame,'0'),num2str(i)),'.jpg'));
    end
    %cropping to extract the useful part of the image
    a=imread(name);
    b=rgb2gray(a);
    b_crop = imcrop(b,[x(1) y(1) x(2)-x(1) y(2)-y(1)]);
    y_line=line_detect_fct(b_crop);
    if isempty(y_line)==0
        j=j+1;
        Time(j)=(j-1)*1/FPS;
        Y(j)=y_line;
    end
    
end
figure
plot(Time,Y,'LineWidth',2)
xlabel('Time [sec]')
ylabel('Amplitude')
title('Choose the peak amplitude points(both -ve and +ve)from left to right. Press Enter when done')
grid on

[X1,Y1]=ginput();
%period of the oscillations
Period=2*mean(X1(2:2:length(X1))-X1(1:2:length(X1)-1));
%compute frequency
Frequency=2*pi/Period;

Contact us