MATLAB Answers

How to save an image using imwrite with a filename from a variable

143 ビュー (過去 30 日間)
Nalini Nadupalli
Nalini Nadupalli 2016 年 10 月 24 日
編集済み: Jan 2018 年 3 月 19 日
I am saving a frame from a video as an image. Both the image and video should have the same name. How can I save an image with a file name from a variable? The filenames are stored in the variable videos.name
videos = dir('*.avi');
for i = 1:size(videos)
[pathstr,name,ext] = fileparts(videos(i).name)
V = VideoReader(videos(i).name);
oneframe = readFrame(V);
imshow(oneframe)
imwrite(oneframe, name, '.jpg')
end
Thank you very much!
  1 件のコメント
Jan
Jan 2018 年 3 月 19 日
[MOVED from flag]
Adam Eshag wrote: "How can I save different preprocessed images in the same folder"
The answer sounds trivial: Provide different file names. Prefer to open a new thread and to add any details about what your problem is.
@Adam: Please use flags only to inform admins and editors about inappropriate contents like spam or rudeness. Thanks.

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

採用された回答

Kirby Fears
Kirby Fears 2016 年 10 月 24 日
編集済み: Kirby Fears 2016 年 10 月 24 日
Hi Nalini,
You can combine string values using square brackets. The syntax for imwrite using your variable names is as follows:
imwrite(oneframe, [name, '.jpg']);
Check your workspace to ensure name is the intended file name without a file extension.
Hope this helps
  1 件のコメント
Nalini Nadupalli
Nalini Nadupalli 2016 年 10 月 24 日
Thanks a ton! This is exactly what I needed

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by