MATLAB Answers

nadia naji

temporal treatment of special row or column of frames in video

Asked by nadia naji
on 24 Feb 2013

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


1 Answer

Answer by Image Analyst
on 24 Feb 2013
 Accepted answer

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.


when i use this code the output is a figure that is withe with some yellow or red point but my image has texture and shouldn't show this output do you have any idea to help me please? i think this code acts as you explain for me but the output of this is the same as the above explanation

 mov(1:nFrames) = ...
    struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
    'colormap', []);
tex(1:nFrames) = ...
    struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'));
for k=1:nFrames
   tex(k).cdata= mov(k).cdata(100,:,:);

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.)
% 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);
	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.
	% 	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);
		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);
		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);
	% 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);

thanks a lot for your answer and i really appreciate for your help

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!