how can I convert many images from m x n x 3 to m x n by rgb2gray?
1 次查看(过去 30 天)
显示 更早的评论
I want to convert 50 .jped images in a folder alltogether
4 个评论
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
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
0 个评论
更多回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!