what changes are to be made in the following code to convert all the images in grayscale?

1 回表示 (過去 30 日間)
images ='C:\Users\TIET\Desktop\tomato'; jpgfiles=dir(fullfile(images,'\*.jpg*')) n=numel(jpgfiles); idx=randi(n); im=jpgfiles(idx).name im1=imread(fullfile(images,im))

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 13 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 13 日
Code: Call the all image in the folder on by one, convert to grayscale and save it one by one in the mentioned path destination(im1,im2,im3,im4......)
path_directory='folder_name_here'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']); %Note on Image Format
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
image_ogi=imread(filename);
gray=rgb2gray(image_ogi);
destination='D:\folder_name_destinatiomn\im'; %Complete path of the folder
imwrite(gray,[destination,num2str(k),'.png']); %Change the image formta as per desired image format
end
  8 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 13 日
Please check carefully, it works!
SHUBHDEEP KAUR
SHUBHDEEP KAUR 2018 年 9 月 13 日
thank you..is in working state now.

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

その他の回答 (0 件)

カテゴリ

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