i have 20 images saved in a folder in computer now i have to convert to gray images at the time. how to convert rgb to gray ?
3 次查看(过去 30 天)
显示 更早的评论
i have 20 images saved in a folder in computer now i have to convert to gray images at the time. how to convert rgb to gray ?
0 个评论
回答(1 个)
Wanbin Song
2015-10-28
Supposed that your images are named as image1.png, image2.png, ... image20.png.
You can do it as follows:
for i = 1:20
img_str = sprintf('image%d.png', i);
temp_gray = rgb2gray(imread(img_str));
img_str = sprintf('gray_image%d.png', i);
imwrite(temp_gray, img_str);
end
Then, converted gray images will be stored in the path as name with 'gray_imgXX.png'.
2 个评论
Wanbin Song
2015-11-2
Is your code could read images correctly and displays it?
I don't think so, but if so, you just add the command 'rgb2gray'.
另请参阅
类别
在 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!