필터 지우기
필터 지우기

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 ?

답변 (1개)

Wanbin Song
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
rohit ranjan
rohit ranjan 2015년 10월 28일
편집: Walter Roberson 2015년 11월 2일
thank u sir for answer me
but my matlab code is
clear all;
close all;
clc;
path='E:\OLD_MYDOCUMENT\prabhu\matcodes\';
list=dir([path, '*.bmp']);
for x=1:length(list)
images{x}=imread([path, list(x).name]);
figure(x), imshow(images{x});
end
after this i have to convert gray image and show all the images. how to do?
Wanbin Song
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 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