Save a sequence of images in a new folder

I have this code:
miFolder='C:\Users\karina\Documents\MATLAB\11';
if ~isdir(miFolder)
errorMensaje = sprintf('Error: El folder no existe:\n%s', miFolder);
uiwait(warndlg(errorMensaje));
return;
end
filePatron = fullfile(miFolder, '*.jpg');
jpegFil = dir(filePatron);
Resultados='C:\Users\karina\Documents\MATLAB\11\SerieN';
mkdir(Resultados);
for k = 1:10
baseFN = jpegFil(k).name;
fullFN = fullfile(miFolder, baseFN);
I=imread(fullFN);
I2=imcrop(I,[167.5 0.5 660 524]);
imwrite(I2,[Resultados,num2str(k),'.png']);
end
Then what I want is to save the images in the C:\Users\karina\Documents\MATLAB\11\SerieN location but the images of the SerieN are saved in the C:\Users\karina\Documents\MATLAB\11. All the images are saved as SerieN1.png, SerieN2.png and so on, that's ok but I need to those images will be saved in the correct folder. Thank you for your time. Regards.

 採用された回答

Image Analyst
Image Analyst 2014 年 7 月 11 日
編集済み: Image Analyst 2017 年 12 月 31 日

2 投票

If you're not going to use fullfile(), and use concatenation like you did, you need to add a trailing space to your folder. It's best to use fullfile() which takes care of all that for you.
baseFileName = sprintf('%d.png', k); % e.g. "1.png"
fullFileName = fullfile(Resultados, baseFileName); % No need to worry about slashes now!
imwrite(I2, fullFileName);

3 件のコメント

Karina
Karina 2014 年 7 月 16 日
Thank you Image Analyst. Can I ask you a favor? I have a problem,I finally ended all my files in Matlab. But now the instruction is to compile and create dll in order to read them in Labview. Do you know something related about this? In fact I already have asked but nobody has answered yet. Also I've researched, but I didn't found the correct way to do this. I hope you can help me. Thank you.
Image Analyst
Image Analyst 2014 年 7 月 16 日
I've just compiled m-files into standalone executables, not DLLs, so I don't think I'm of much help there. Call the Mathworks and ask them. The compiler is very expensive so you might as well get something for your support payment.
Githae Wanyawira
Githae Wanyawira 2017 年 12 月 31 日
Thanks Analyst for the great assistance

サインインしてコメントする。

その他の回答 (2 件)

Ali Noori
Ali Noori 2015 年 6 月 12 日
編集済み: Walter Roberson 2015 年 6 月 12 日

1 投票

For example, if you have video (video.avi) in matlab directory and you want to convert this video into frame sequences and save them in new folder (IMAGESEQUENCES). write this code below:
%%code %%
video = VideoReader('video.avi');
OutVideoDir = 'IMAGESEQUENCES';
mkdir(OutVideoDir);
for i = 1:video.NumberOfFrames
img = read(video,i);
baseFileName = sprintf('%d.png', i); % e.g. "1.png"
fullFileName = fullfile(OutVideoDir, baseFileName);
imwrite(img, fullFileName);
end
David Young
David Young 2014 年 7 月 11 日

0 投票

Instead of
imwrite(I2,[Resultados,num2str(k),'.png']);
try
imswrite(I2, fullfile(Resultados, ['SerieN', num2str(k), '.png']));

1 件のコメント

Karina
Karina 2014 年 7 月 16 日
Thank you David it was so helpful

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2014 年 7 月 11 日

編集済み:

2017 年 12 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by