How to save multiple images using imwrite in matlab ?

How to save multiple images gray format .jpeg using imwrite in matlab ?
image_folder ='E:\gambar_eror'
filenames = dir (fullfile(image_folder,'*.jpeg'))
total_images = numel(filenames);
%training=[];
for n= 1:total_images;
f= fullfile(image_folder, filenames(n).name);
disp(f);
our_images= imread (f);
size (our_images);
gray=rgb2gray(our_images);
end

 采纳的回答

image_folder ='E:\gambar_eror'
filenames = dir (fullfile(image_folder,'*.jpeg'))
total_images = numel(filenames);
%training=[];
for n= 1:total_images;
f= fullfile(image_folder, filenames(n).name);
disp(f);
[FILEPATH,NAME,EXT] = fileparts(f) ;
our_image= imread (f);
gray=rgb2gray(our_image);
filename = [image_folder,'\',NAME,'_gray',EXT] ;
imwrite(gray,filename)
end

5 个评论

how do i see the result of saving a jpeg image file?
The images with names which already existing and appened by _gray should be in the folder....NO?
oh i see right. already in the same folder.
may i ask the meaning of
[Filepath,name,ext]= fileparts(f);
and
filename =[image_folder,'\',name,'_gray',ext];
You can read the documentation. Read about those functions.
fileparts: This gives, the path of the file, name of the file and extension of the file.
[]: This will join the strings. This line, creates the image name.
Okay. Thankyou so much for the answer and discussion.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Images 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by