Read image and save it using imwrite?

11 ビュー (過去 30 日間)
Teemu
Teemu 2013 年 3 月 14 日
Hello! I read pictures using imread and then try to write it to folder c:\result. The name of the images should be same than readed image, but I like to add index and remove part of the name. So I read image image00123_big.bmp and I like to save image to name image00123_small_'index_number'.bmp. How can I do that?

採用された回答

ChristianW
ChristianW 2013 年 3 月 14 日
Input_folder = '.\'; % folder with big images
Output_folder = 'c:\result';
D = dir([Input_folder 'image*_big.bmp']);
Inputs = {D.name}';
Outputs = Inputs; % preallocate
for k = 1:length(Inputs)
X = imread([Input_folder Inputs{k}]);
idx = k; % index number
Outputs{k} = regexprep(Outputs{k}, 'big', ['small_' num2str(idx)]);
imwrite(X, [Output_folder Outputs{k}],'bmp')
end

その他の回答 (1 件)

Alessandro
Alessandro 2013 年 3 月 14 日
編集済み: Alessandro 2013 年 3 月 15 日
id = 5;
folder = 'c:\result\'
newimagename = [folder 'image00123_small_' num2str(id) '.bmp'];
imwrite(image,newimagename)
  4 件のコメント
Jan
Jan 2013 年 3 月 14 日
Do not shadow the important Matlab function path by a local variable. This can leed to very strange effects e.g. during debugging.
Image Analyst
Image Analyst 2013 年 3 月 14 日
Use "folder" instead of "path" for a variable name. Don't use "dir" either - it's a built in function.

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by