Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: write images to different folders
Replies: 2   Last Post: Dec 11, 2012 12:42 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,945
Registered: 12/7/04
Re: write images to different folders
Posted: Dec 7, 2012 9:30 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"GITTO THAMPI" <gittothampi@yahoo.in> wrote in message
> i'm doing a work in frame extraction from video. i want to save the
> extracted frames to many subfolders that exists in a particular
> location(not current directory). I want to save the first 75 extracted
> frames in subfolder1, the next 75 frames in subfolder2, and so on... this
> is the code i have written..
> xyloObj = mmreader('F:short\mov1.mpg');
> nFrames = xyloObj.NumberOfFrames;
> disp(nFrames);
> n=1;
> % Read one frame at a time.
> for j = 1 : (nFrames/75)
> foldername=strcat('mov1seg',int2str(j));
> f1=fullfile('F:xylo\mov1\',foldername);

So f1 starts with F:xylo\mov1\mov1seg1 and continues with
F:xylo\mov1\mov1seg2, etc. [BTW you may be missing a \ just after F:]

> mkdir(f1);

The directory is created.

> for k=n: n+74
> mov(k).cdata = read(xyloObj, k);
> mov(k).colormap = [];
> %imshow(mov(k).cdata);
> imagename=strcat(int2str(k), '.jpeg');
> imwrite(mov(k).cdata, strcat('F:xylo\mov1\mov1seg',int2str(j),imagename));

This doesn't do quite what you think it does. Let's say j = 1 and k = 1.
What does the STRCAT call return?

j = 1;
k = 1;
imagename=strcat(int2str(k), '.jpeg');
whereToWrite = strcat('F:xylo\mov1\mov1seg',int2str(j),imagename)


That's NOT where you wanted to write the file. You're missing the separator
between the directory name and the file name. Some comments:

1) You already have the first part of your STRCAT call; you defined it above
as f1. Why recreate that string in your IMWRITE call? Just use f1!
2) You used FULLFILE in the construction of f1. Why didn't you use it
instead of STRCAT? FULLFILE handles adding in the separator automatically.

imwrite(mov(k).cdata, fullfile(f1, imagename));

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.