temporal treatment of special row or column of frames in video

1 view (last 30 days)
hi i have a video and i want to consider the action of sequential frames for special x and all y with that x. this means instead i show xy plane in each frame i want to see yt plane for x=120 in sequential frame in video how can i do this?(if my frame size in 240x320 i want to see yt plane for x=120 means the temporal treatment of x=120 for frames)please help me

Accepted Answer

Image Analyst
Image Analyst on 24 Feb 2013
Initialize an accumulation array of the same height and number of colors, and the number of frames will be the columns direction. Read in each frame (search this forum for rhinos.avi for my demo), then extract a column and insert it into your accumulation array where the column number to insert is the frame number you're on. Let me know if you can't figure it out from that description.
  5 Comments
Image Analyst
Image Analyst on 24 Feb 2013
nadia, this forum has a search capability at the very top right of this page. You can type things into there and it will retrieve messages related to your search terms. That's what I wanted you to do. Nonetheless, I just did it for you. Here is your code (adapt it as needed):
% Demo macro to extract frames from an avi movie
% and get a column from each frame and plot it as an image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Open the rhino.avi demo movie that ships with MATLAB.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
movieFullFileName = fullfile(folder, 'rhinos.avi');
% Check to see that it exists.
if ~exist(movieFullFileName, 'file')
strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new one, or cancel', movieFullFileName);
response = questdlg(strErrorMessage, 'File not found', 'OK - choose a new movie.', 'Cancel', 'OK - choose a new movie.');
if strcmpi(response, 'OK - choose a new movie.')
[baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
if ~isequal(baseFileName, 0)
movieFullFileName = fullfile(folderName, baseFileName);
else
return;
end
else
return;
end
end
try
videoObject = VideoReader(movieFullFileName)
% Determine how many frames there are.
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
numberOfFramesWritten = 0;
% Prepare a figure to show the images in the upper half of the screen.
figure;
% screenSize = get(0, 'ScreenSize');
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Loop through the movie, writing all frames out.
% Each frame will be in a separate file with unique name.
columnToExtract = int32(100);
ytImage = zeros(vidHeight, numberOfFrames, 2, 'uint8');
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = read(videoObject, frame);
% Display it
hImage = subplot(1, 2, 1);
image(thisFrame);
caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
title(caption, 'FontSize', fontSize);
% Plot the line over it.
line([columnToExtract, columnToExtract], [1, vidHeight], 'Color', 'r');
drawnow; % Force it to refresh the window.
% Extract the column from this frame.
thisColumn = squeeze(thisFrame(:, columnToExtract, :));
% Stick the column in our accumulation array.
ytImage(:,frame, 1) = thisColumn(:, 1);
ytImage(:,frame, 2) = thisColumn(:, 2);
ytImage(:,frame, 3) = thisColumn(:, 3);
% Plot the Y vs. Time image.
subplot(1, 2, 2);
imshow(ytImage);
title('Y vs. Time (Frame number) Image', 'FontSize', fontSize);
xlabel('Time (frame number)', 'FontSize', fontSize);
ylabel('Row (Line)', 'FontSize', fontSize);
axis on;
% Update user with the progress. Display in the command window.
progressIndication = sprintf('Processed frame %4d of %d.', frame, numberOfFrames);
disp(progressIndication);
end
% Alert user that we're done.
finishedMessage = sprintf('Done! It processed %d frames of\n"%s"', numberOfFramesWritten, movieFullFileName);
disp(finishedMessage); % Write to command window.
uiwait(msgbox(finishedMessage)); % Also pop up a message box.
msgbox('Done with this demo!');
catch ME
% Some error happened if you get here.
stError = lasterror;
strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n\nError: %s\n\n)', movieFullFileName, stError.message);
uiwait(msgbox(strErrorMessage));
end
nadia naji
nadia naji on 25 Feb 2013
thanks a lot for your answer and i really appreciate for your help

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!