MATLAB: Read image and save it using imwrite

digital image processingimwrite

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?

Best Answer

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