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.

댓글을 달려면 로그인하십시오.

채택된 답변

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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by