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

 採用された回答

KSSV
KSSV 2022 年 5 月 31 日
編集済み: KSSV 2022 年 5 月 31 日

0 投票

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 件のコメント

Armylia Dewi
Armylia Dewi 2022 年 5 月 31 日
how do i see the result of saving a jpeg image file?
KSSV
KSSV 2022 年 5 月 31 日
The images with names which already existing and appened by _gray should be in the folder....NO?
Armylia Dewi
Armylia Dewi 2022 年 5 月 31 日
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];
KSSV
KSSV 2022 年 5 月 31 日
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.
Armylia Dewi
Armylia Dewi 2022 年 5 月 31 日
Okay. Thankyou so much for the answer and discussion.

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2018a

質問済み:

2022 年 5 月 31 日

コメント済み:

2022 年 5 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by