From: Nathan on
On Apr 20, 5:45 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> Nathan <ngrec...(a)gmail.com> wrote in message <76e32902-0a40-4629-8b64-0e807d62e...(a)p35g2000prf.googlegroups.com>...
> > On Apr 20, 5:09 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> > > Nathan <ngrec...(a)gmail.com> wrote in message <caacae63-9839-48e9-ae63-2fdcd14f5...(a)w20g2000prm.googlegroups.com>...
> > > > On Apr 20, 4:49 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> > > > > hi every one actually I need to save a lot of images using matlab but I don't know how.
> > > > > here is my code
> > > > > % READ THE AVI
> > > > > mov=aviread('timelapsevideo_1.avi');
> > > > > % GRAB A SINGLE FRAME
> > > > > for i=1:5
> > > > > figure;
> > > > > [im1,map] = frame2im(mov(i));
> > > > > % SHOW THE FRAME
> > > > > figure(i);
> > > > > imshow( im1 );
> > > > > imwrite(im1(i),'Frame1.bmp');
>
> > > > > end
>
> > > > try replacing:
> > > > imwrite(im1(i),'Frame1.bmp');
> > > > with
> > > > imwrite(im1(i),sprintf('Frame%d.bmp',i));
>
> > > > Is that your only problem?
>
> > > > -Nathan
>
> > > yah it solved my problem of saving alot of images but they are not saving correctly which mean the picture not shown ,I thought the problem from the colormap so I putted above it and I still have the same problem ,here is my code so u can understand more
> > >   for i=1:1
> > >     figure;
> > >     [im1,map] = frame2im(mov(i));
> > >     % SHOW THE FRAME
> > >     figure(i);
> > >     imshow( im1 );
> > >     colormap(map);  <-----------------------------------------------here is the what I mean
> > >     imwrite(im1(i),sprintf('Frame%d.bmp',i))
>
> > >     end
> > > Thanks man .
>
> > Note that the imwrite command has a MAP parameter...
>
> > Try:
> > imwrite(im1(i),map,sprintf('Frame%d.bmp',i))
>
> > -Nathan
>
> I got the following error
>
> ??? Error using ==> imwrite at 378
> Invalid colormap
>
> Error in ==> testCam at 12
>     imwrite(im1(i),map,sprintf('Frame%d.bmp',i))

I don't know what to tell you, then.

Hopefully someone else will come along to assist you. I'm heading
home.

-Nathan
From: Saied on
Nathan <ngreco32(a)gmail.com> wrote in message <f4bdaebc-b1d1-476a-88cf-4c6cabd4f560(a)u9g2000prm.googlegroups.com>...
> On Apr 20, 5:45 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> > Nathan <ngrec...(a)gmail.com> wrote in message <76e32902-0a40-4629-8b64-0e807d62e...(a)p35g2000prf.googlegroups.com>...
> > > On Apr 20, 5:09 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> > > > Nathan <ngrec...(a)gmail.com> wrote in message <caacae63-9839-48e9-ae63-2fdcd14f5...(a)w20g2000prm.googlegroups.com>...
> > > > > On Apr 20, 4:49 pm, "Saied " <kezman_...(a)yahoo.com> wrote:
> > > > > > hi every one actually I need to save a lot of images using matlab but I don't know how.
> > > > > > here is my code
> > > > > > % READ THE AVI
> > > > > > mov=aviread('timelapsevideo_1.avi');
> > > > > > % GRAB A SINGLE FRAME
> > > > > > for i=1:5
> > > > > > figure;
> > > > > > [im1,map] = frame2im(mov(i));
> > > > > > % SHOW THE FRAME
> > > > > > figure(i);
> > > > > > imshow( im1 );
> > > > > > imwrite(im1(i),'Frame1.bmp');
> >
> > > > > > end
> >
> > > > > try replacing:
> > > > > imwrite(im1(i),'Frame1.bmp');
> > > > > with
> > > > > imwrite(im1(i),sprintf('Frame%d.bmp',i));
> >
> > > > > Is that your only problem?
> >
> > > > > -Nathan
> >
> > > > yah it solved my problem of saving alot of images but they are not saving correctly which mean the picture not shown ,I thought the problem from the colormap so I putted above it and I still have the same problem ,here is my code so u can understand more
> > > >   for i=1:1
> > > >     figure;
> > > >     [im1,map] = frame2im(mov(i));
> > > >     % SHOW THE FRAME
> > > >     figure(i);
> > > >     imshow( im1 );
> > > >     colormap(map);  <-----------------------------------------------here is the what I mean
> > > >     imwrite(im1(i),sprintf('Frame%d.bmp',i))
> >
> > > >     end
> > > > Thanks man .
> >
> > > Note that the imwrite command has a MAP parameter...
> >
> > > Try:
> > > imwrite(im1(i),map,sprintf('Frame%d.bmp',i))
> >
> > > -Nathan
> >
> > I got the following error
> >
> > ??? Error using ==> imwrite at 378
> > Invalid colormap
> >
> > Error in ==> testCam at 12
> >     imwrite(im1(i),map,sprintf('Frame%d.bmp',i))
>
> I don't know what to tell you, then.
>
> Hopefully someone else will come along to assist you. I'm heading
> home.
>
> -Nathan
thank you very much Nathan ,really appreciate your help,and hope some can assist me or help me.
From: ImageAnalyst on
Try this demo that I've posted many times before:
(Be sure to join any lines split into two by the newsreader)

% Demo macro to extract frames from an avi movie to separate files.
% by ImageAnalyst
clc;
close all;
% Open the rhino.avi demo movie that ships with MATLAB.
movieFullFileName = 'C:\Program Files\MATLAB\R2010a\toolbox\images
\imdemos\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
mov = aviread(movieFullFileName);
% movie(mov);
% Make a special output folder to hold all the separate movie frames
% as their own image files.
outputFolder = fullfile(cd, 'Rhino Movie');
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;
% Prepare a figure to show the images.
figure;
screenSize = get(0, 'ScreenSize');
newWindowPosition = [1 1 screenSize(3)/2 screenSize(4)/2];
set(gcf, 'Position', newWindowPosition); % Maximize figure.
% Loop through the movie, writing all frames out.
% Each frame will be in a separate file with unique name.
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = mov(frame).cdata;
% Display it
image(thisFrame);
drawnow; % Force it to refresh the window.
% Construct an output iamge file name.
outputBaseFileName = sprintf('Frame %4.4d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
% Write the image array to the output file.
imwrite(thisFrame, outputFullFileName, 'png');
% Update user with the progress. Display in the command window.
progressIndication = sprintf('Wrote frame %4d of %d.', frame,
numberOfFrames);
disp(progressIndication);
% Increment frame count (should eventually = numberOfFrames
% unless an error happens).
numberOfFramesWritten = numberOfFramesWritten + 1;
end
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);
msgboxw(strErrorMessage);
end
% Alert user that we're done.
finishedMessage = sprintf('Done! It wrote %d frames to folder\n"%s"',
numberOfFramesWritten, outputFolder);
disp(finishedMessage); % Write to command window.
msgbox(finishedMessage); % Also pop up a message box.