what changes are to be made in the following code to convert all the images in grayscale?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SHUBHDEEP KAUR
am 13 Sep. 2018
Kommentiert: SHUBHDEEP KAUR
am 13 Sep. 2018
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))
0 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 13 Sep. 2018
Bearbeitet: KALYAN ACHARJYA
am 13 Sep. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!