how can I convert many images from m x n x 3 to m x n by rgb2gray?

4 ビュー (過去 30 日間)
Bajdar Nour
Bajdar Nour 2020 年 4 月 3 日
回答済み: Image Analyst 2020 年 4 月 4 日
I want to convert 50 .jped images in a folder alltogether
  4 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 4 月 3 日
You would need to come up with a naming convention for the grayscale images and/or determine where these new files should be written to.
Bajdar Nour
Bajdar Nour 2020 年 4 月 4 日
thanks again

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

採用された回答

KSSV
KSSV 2020 年 4 月 4 日
img = dir('*.jpeg') ;
N = length(img) ;
for i = 1:N
thisimg = img(i).name ;
I = imread(thisimg) ;
Ig = rgb2gray(I) ;
[dir,name,ext] = fileparts(thisimg) ;
filename = [name,'_gray','.jpeg'] ;
imwrite(Ig,filename) ;
end

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 4 日
See the FAQ
In the loop, use sprintf() to build up your filename and use rgb2gray() if ndims() of the image is 3.

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by